## [1] "!! high !! The experiment investigate the effects of two disturbance levels: low and high. To make it easier to interpet, we showcase only one of the two disturbance levels. In this document we showcase only the high disturbance)"
Ecosystem size is a key factor driving biodiversity and ecosystem function. Larger ecosystems contain more species and can be hubs of dispersal and resource flows in networks of multiple ecosystems. However, whether and how ecosystem size and resource flows interact to affect biodiversity and ecosystem function has been largely overlooked. Here, we investigated how ecosystem size asymmetry affects biodiversity and function of two-ecosystem meta-ecosystems connected through flows of non-living resources. We conducted microcosm experiments, mimicking resource flows between ecosystems of different sizes, yet otherwise being identical. We found that meta-ecosystems with asymmetric ecosystem sizes had higher β-diversity but lower α-diversity and ecosystem function (total biomass) than their unconnected counterparts, while such an effect was not found for meta-ecosystems of identical ecosystem sizes. Our work demonstrates of how cross-ecosystem dynamics modulated by differences in ecosystem sizes affect biodiversity and function, with a direct implication for conservation and management of connected ecosystems.
Parameters for R markdown and the general running of the code.
start_time = Sys.time()
knitr::opts_chunk$set(message = FALSE,
cache = FALSE,
autodep = FALSE)
recompute_lengthy_analyses = FALSE
plot_model_residuals_metaecos = FALSE
Parameters related to resource flows.
disturbance_levels = c("low", "high")
n_disturbance_levels = length(disturbance_levels)
resource_flow_days = c(5, 9, 13, 17, 21, 25)
first_resource_flow = resource_flow_days[1]
Parameters related to sampling.
total_frames = 125
volume_recorded_μl = 34.4
time_points = 0:7
time_points_without_t0 = 1:7
time_point_names = c("t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7")
sampling_days = c(0, 4, 8, 12, 16, 20, 24, 28)
first_time_point = 0
last_time_point = length(sampling_days) - 1
n_time_points = last_time_point + 1
nr_videos = c(12, 1, 1, 1, 1, 1, 2, 2) #Videos taken for each time point for each culture. At t0 we took 12 videos of the large bottle from which we started the cultures. Write why 2 at the end.
videos_taken = data.frame(time_point = 0 : 7,
nr_videos = c(12, 1, 1, 1, 1, 1, 2, 2))
n_videos_taken_t0 = nr_videos[1]
time_point_day = data.frame(time_point = first_time_point:last_time_point,
day = sampling_days,
video_replicates = nr_videos)
videos_to_take_off = data.frame(culture_ID = NA,
time_point = NA,
file = NA) %>%
add_row(culture_ID = 137-110,
time_point = 7,
file = 137) %>%
slice(-1)
n_cultures = 110
total_number_of_video_rows = sum(nr_videos * n_cultures)
Parameters related to protists.
protist_species = c("Ble", "Cep", "Col", "Eug", "Eup", "Lox", "Pau", "Pca", "Spi", "Spi_te", "Tet")
protist_species_indiv_per_volume = paste0(protist_species, "_indiv_per_volume")
protist_species_indiv_per_ml = paste0(protist_species, "_indiv_per_ml")
protist_species_dominance = paste0(protist_species_indiv_per_ml, "_dominance")
protist_species_total = paste0(protist_species, "_tot_indiv")
n_protist_species = length(protist_species)
first_protist = protist_species[1]
last_protist = protist_species[n_protist_species]
species_IDD_with_13_threshold = c("Col", "Eug", "Eup", "Lox", "Pau", "Pca", "Spi_te", "Tet")
species_IDD_with_13_threshold_indiv_per_volume = paste0(species_IDD_with_13_threshold, "_indiv_per_volume")
species_IDD_with_40_threshold = c("Ble", "Cep", "Spi")
species_IDD_with_40_threshold_indiv_per_volume = paste0(species_IDD_with_40_threshold, "_indiv_per_volume")
Parameters related to ecosystems.
ecosystems_to_take_off = 60 #Culture ID = 60 as it was spilled (small unconnected, high disturbance, system nr = 40)
ecosystems_info = read.csv(here("2_data", "ecosystems_info.csv"), header = TRUE)
columns_ecosystems = c("time_point",
"day",
"culture_ID",
"system_nr",
"disturbance",
"ecosystem_type",
"connection",
"ecosystem_size",
"ecosystem_size_ml",
"metaecosystem",
"metaecosystem_type")
columns_treatments = columns_ecosystems[!columns_ecosystems %in% c("system_nr", "culture_ID")]
variables_ecosystems = c("bioarea_mm2_per_ml",
"bioarea_tot_mm2",
"indiv_per_ml",
"indiv_tot",
"species_richness",
"shannon",
"simpson",
"inv_simpson",
"evenness_pielou",
"median_body_area_µm2",
paste0(protist_species, "_indiv_per_ml"),
paste0(protist_species, "_tot_indiv"),
paste0(protist_species_indiv_per_ml, "_dominance"))
baseline_columns = paste0("baseline_", variables_ecosystems)
ecosystem_types_ordered = c("Small connected to large",
"Small connected to small",
"Small unconnected",
"Medium connected to medium",
"Medium unconnected",
"Large connected to small",
"Large connected to large",
"Large unconnected")
treatments_and_controls = data.frame(treatment = c("Small connected to small",
"Small connected to large",
"Medium connected to medium",
"Large connected to large",
"Large connected to small"),
control = c("Small unconnected",
"Small unconnected",
"Medium unconnected",
"Large unconnected",
"Large unconnected"))
n_treatments = length(unique(treatments_and_controls$treatment))
n_controls = length(unique(treatments_and_controls$control))
n_replicates = 5
n_ecosystem_types = 8
Parameters related to size classes.
n_size_classes = 12
columns_classes = c(columns_ecosystems,
"size_class_n",
"mean_class_area_µm2")
Parameters related to meta-ecosystems.
metaecosystems_to_take_off = ecosystems_info %>%
filter(culture_ID %in% ecosystems_to_take_off) %>%
pull(system_nr) %>%
unique
system_nr_metaecosystems = ecosystems_info %>%
filter(metaecosystem == "yes") %>%
pull(system_nr) %>%
unique
n_metaecosystems = length(system_nr_metaecosystems)
variables_metaecos = c(
"total_metaecosystem_bioarea_mm2",
"jaccard_index",
"bray_curtis",
"beta_spatial_turnover",
"beta_nestedness",
"beta_total",
"metaecosystem_richness")
metaecosystem_types_ordered = c(
"Small-Small meta-ecosystem",
"Medium-Medium meta-ecosystem",
"Medium-Medium unconnected",
"Large-Large meta-ecosystem",
"Small-Large meta-ecosystem",
"Small-Large unconnected")
Name of the axes per response variable.
axis_names = data.frame(variable = NA,
axis_name= NA) %>%
add_row(variable = "day", axis_name = "Time (day)") %>%
add_row(variable = "ecosystem_size_ml", axis_name = "Patch size (ml)") %>%
add_row(variable = "log_size_class", axis_name = "Log size (μm2)") %>%
add_row(variable = "class_indiv_per_µl", axis_name = "Density (ind/ml)") %>%
add_row(variable = "bioarea_mm2_per_ml", axis_name = "Biomass (mm2/ml)") %>%
add_row(variable = "bioarea_mm2_per_ml_d", axis_name = "Bioamass ES") %>%
add_row(variable = "bioarea_tot", axis_name = "Total Biomass (mm2)") %>%
add_row(variable = "total_metaecosystem_bioarea_mm2", axis_name = "Total Biomass (mm2)") %>%
add_row(variable = "species_richness", axis_name = "Species Richness") %>%
add_row(variable = "species_richness_d", axis_name = "Species Richness ES") %>%
add_row(variable = "mean_richness", axis_name = "Mean α-Diversity (Shannon)") %>%
add_row(variable = "mean_shannon", axis_name = "Mean α-Diversity (Shannon)") %>%
add_row(variable = "shannon", axis_name = "Biodiversity (Shannon)") %>%
add_row(variable = "shannon_d", axis_name = "Biodiversity ES (Shannon ES)") %>%
add_row(variable = "bray_curtis", axis_name = "β-Diversity (Bray-Curtis)") %>%
add_row(variable = "beta_spatial_turnover", axis_name = "Turn over (Simpson pair-wise dissimilarity)") %>%
add_row(variable = "beta_nestedness", axis_name = "Nestedness (nestedness-fraction of Sorensen)") %>%
add_row(variable = "beta_total", axis_name = "Tot β-Diversity (Sorensen)") %>%
add_row(variable = "metaecosystem_richness", axis_name = "γ-Diversity (Species Richness)") %>%
add_row(variable = "indiv_per_ml", axis_name = "Abundance (ind/ml)") %>%
add_row(variable = "indiv_per_ml_d", axis_name = "Abundance ES") %>%
add_row(variable = "median_body_area_µm2", axis_name = "Median Body Size (µm²)") %>%
add_row(variable = "median_body_area_µm2_d", axis_name = "Median Body Size ES") %>%
add_row(variable = "Ble_indiv_per_ml", axis_name = "Ble Density (ind/ml)") %>%
add_row(variable = "Cep_indiv_per_ml", axis_name = "Cep Density (ind/ml)") %>%
add_row(variable = "Col_indiv_per_ml", axis_name = "Col Density (ind/ml)") %>%
add_row(variable = "Eug_indiv_per_ml", axis_name = "Eug Density (ind/ml)") %>%
add_row(variable = "Eup_indiv_per_ml", axis_name = "Eup Density (ind/ml)") %>%
add_row(variable = "Lox_indiv_per_ml", axis_name = "Lox Density (ind/ml)") %>%
add_row(variable = "Pau_indiv_per_ml", axis_name = "Pau Density (ind/ml)") %>%
add_row(variable = "Pca_indiv_per_ml", axis_name = "Pca Density (ind/ml)") %>%
add_row(variable = "Spi_indiv_per_ml", axis_name = "Spi Density (ind/ml)") %>%
add_row(variable = "Spi_te_indiv_per_ml", axis_name = "Spi te Density (ind/ml)") %>%
add_row(variable = "Tet_indiv_per_ml", axis_name = "Tet Density (ind/ml)") %>%
add_row(variable = "auto_hetero_ratio", axis_name = "Photosynthetisers-Heterotrops Ratio") %>%
add_row(variable = "Ble_indiv_per_ml_d", axis_name = "Ble Density ES") %>%
add_row(variable = "Cep_indiv_per_ml_d", axis_name = "Cep Density ES") %>%
add_row(variable = "Col_indiv_per_ml_d", axis_name = "Col Density ES") %>%
add_row(variable = "Eug_indiv_per_ml_d", axis_name = "Eug Density ES") %>%
add_row(variable = "Eup_indiv_per_ml_d", axis_name = "Eup Density ES") %>%
add_row(variable = "Lox_indiv_per_ml_d", axis_name = "Lox Density ES") %>%
add_row(variable = "Pau_indiv_per_ml_d", axis_name = "Pau Density ES") %>%
add_row(variable = "Pca_indiv_per_ml_d", axis_name = "Pca Density ES") %>%
add_row(variable = "Spi_indiv_per_ml_d", axis_name = "Spi Density ES") %>%
add_row(variable = "Spi_te_indiv_per_ml_d", axis_name = "Spi te Density ES") %>%
add_row(variable = "Tet_indiv_per_ml_d", axis_name = "Tet Density ES") %>%
add_row(variable = "Ble_indiv_per_ml_dominance", axis_name = "Ble Dominance (%)") %>%
add_row(variable = "Cep_indiv_per_ml_dominance", axis_name = "Cep Dominance (%)") %>%
add_row(variable = "Col_indiv_per_ml_dominance", axis_name = "Col Dominance (%)") %>%
add_row(variable = "Eug_indiv_per_ml_dominance", axis_name = "Eug Dominance (%)") %>%
add_row(variable = "Eup_indiv_per_ml_dominance", axis_name = "Eup Dominance (%)") %>%
add_row(variable = "Lox_indiv_per_ml_dominance", axis_name = "Lox Dominance (%)") %>%
add_row(variable = "Pau_indiv_per_ml_dominance", axis_name = "Pau Dominance (%)") %>%
add_row(variable = "Pca_indiv_per_ml_dominance", axis_name = "Pca Dominance (%)") %>%
add_row(variable = "Spi_indiv_per_ml_dominance", axis_name = "Spi Dominance (%)") %>%
add_row(variable = "Spi_te_indiv_per_ml_dominance", axis_name = "Spi te Dominance (%)") %>%
add_row(variable = "Tet_indiv_per_ml_dominance", axis_name = "Tet Dominance (%)") %>%
add_row(variable = "Ble_indiv_per_ml_dominance_d", axis_name = "Ble Dominance ES") %>%
add_row(variable = "Cep_indiv_per_ml_dominance_d", axis_name = "Cep Dominance ES") %>%
add_row(variable = "Col_indiv_per_ml_dominance_d", axis_name = "Col Dominance ES") %>%
add_row(variable = "Eug_indiv_per_ml_dominance_d", axis_name = "Eug Dominance ES") %>%
add_row(variable = "Eup_indiv_per_ml_dominance_d", axis_name = "Eup Dominance ES") %>%
add_row(variable = "Lox_indiv_per_ml_dominance_d", axis_name = "Lox Dominance ES") %>%
add_row(variable = "Pau_indiv_per_ml_dominance_d", axis_name = "Pau Dominance ES") %>%
add_row(variable = "Pca_indiv_per_ml_dominance_d", axis_name = "Pca Dominance ES") %>%
add_row(variable = "Sp_indiv_per_mli_dominance_d", axis_name = "Spi Dominance ES") %>%
add_row(variable = "Spi_te_indiv_per_ml_dominance_d", axis_name = "Spi te Dominance ES") %>%
add_row(variable = "Tet_indiv_per_ml_dominance_d", axis_name = "Tet Dominance ES") %>%
add_row(variable = "dominance", axis_name = "Dominance (%)") %>%
add_row(variable = "log_abundance", axis_name = "Log Abundance + 1 (ind/mm²)") %>%
add_row(variable = "abundance_hedges_d", axis_name = "Density ES") %>%
add_row(variable = "beta_diversity_from_unconnected", axis_name = "Divergence from unconnected") %>%
add_row(variable = "beta_diversity_from_previous_time", axis_name = "Temporal Divergence") %>%
add_row(variable = "beta_diversity_from_previous_time_d", axis_name = "Temporal Divergence ES") %>%
add_row(variable = "evenness_pielou", axis_name = "Evenness") %>%
add_row(variable = "evenness_pielou_d", axis_name = "Evenness ES") %>%
slice(-1)
Colour and line type per ecosystem/meta-ecosystem type.
treatment_colours = c("Small" = "#feb24c",
"Medium" = "#1b7837",
"Large" = "#3182bd",
"Small-Small" = "#fc9272",
"Large-Large" = "#67000d",
"Small-Large" = "#762a83",
"Medium-Medium" = "#1b7837",
"symmetric" = "#1b7837",
"asymmetric" = "#762a83")
treatment_linetype = c("connected to small" = "solid",
"connected to medium" = "dashed",
"connected to large" = "longdash",
"connected" = "solid",
"unconnected" = "dotted")
Parameters for plotting.
figures_height_rmd_output = 7
legend_position = "top"
legend_width_cm = 2
size_legend = 12
size_x_axis = 13
size_y_axis = size_x_axis
boxplot_width = 2
dodging = 0.5
width_errorbar = 0.2
dodging_error_bar = 0.5
treatment_lines_linewidth = 1
treatment_points_size = 2.5
resource_flow_line_type = "solid"
resource_flow_line_colour = "#d9d9d9"
resource_flow_line_width = 0.3
zero_line_colour = "grey"
zero_line_line_type = "dotted"
zero_line_line_width = 0.5
zero_line_ES_line_type = "dotted"
zero_line_ES_colour = "grey"
zero_line_ES_line_width = 1
ggarrange_margin_top = 0
ggarrange_margin_bottom = 0
ggarrange_margin_left = 0
ggarrange_margin_right = 0
paper_width = 17.3
paper_height = 20
paper_units = "cm"
paper_res = 600
paper_y_axis_size = 9
paper_labels_size = 9
presentation_figure_size = 15
presentation_figure_width = 30
presentation_figure_height = 22
presentation_legend_size = 20
presentation_x_axis_size = 22
presentation_y_axis_size = presentation_x_axis_size
presentation_axes_size = 12
presentation_treatment_points_size = 5
presentation_treatment_linewidth = 2
presentation_figure_units = "cm"
presentation_figure_res = 600
grey_background_xmin = -Inf
grey_background_xmax = 7.5
grey_background_ymin = -Inf
grey_background_ymax = Inf
grey_background_fill = "#f0f0f0"
grey_background_alpha = 0.03
grey_background_color = "transparent"
Parameters for modelling.
time_point_of_baselines = 1
time_points_with_water_addtion = 3:7
time_points_model = time_points_with_water_addtion
optimizer_input = 'Nelder_Mead'
method_input = ''
ecosystems_info)We start by importing the information about the 110 ecosystems of the experiment.
ecosystems_info = read.csv(here("2_data", "ecosystems_info.csv"), header = TRUE)
In this dataset (ds_individuals) each row represents an
individual at a time point.
# Import the individual data of t0. We considered cultures to be all the same at the beginning (t0). Because of this reason, we filmed only the bottles from which cultures were assembled. Because we want to plot also t0 for the different treatments, we want to assign the video of bottles to all cultures at t0.
ds_individuals_t0_not_elongated = read.csv(here("2_data",
"individuals_13_threshold",
"t0.csv")) %>%
mutate(time_point = as.numeric(str_extract(time_point, "\\d+")),
day = 0,
file = as.numeric(str_extract(file, "\\d+")),
video_replicate = file) %>%
select(time_point,
day,
video_replicate,
file,
id,
N_frames,
mean_area)
ds_individuals_t0_elongated = ds_individuals_t0_not_elongated %>%
map_dfr(.x = 1 : nrow(ecosystems_info),
.f = ~ ds_individuals_t0_not_elongated) %>%
arrange(id) %>% #Id refers to an individual
mutate(culture_ID = rep(1 : nrow(ecosystems_info),
times = nrow(ds_individuals_t0_not_elongated))) %>%
select(time_point,
day,
video_replicate,
file,
culture_ID,
id,
N_frames,
mean_area)
expect_equal(nrow(ds_individuals_t0_not_elongated) * nrow(ecosystems_info),
nrow(ds_individuals_t0_elongated))
#Import t1-t4
ds_individuals_t1_to_t4 = NULL
for (time_point_i in time_points_without_t0) {
ds_individuals_t1_to_t4[[time_point_i]] = read.csv(here("2_data",
"individuals_13_threshold",
paste0("t",
time_point_i,
".csv"))) %>%
mutate(time_point = as.numeric(str_extract(time_point, "\\d+")),
day = time_point_day$day[time_point_day$time_point == time_point_i],
file = as.numeric(str_extract(file, "\\d+")),
video_replicate = ceiling(file/n_cultures)) #Until 110 video replicate = 1, then 2
}
ds_individuals_t1_to_t4 = ds_individuals_t1_to_t4 %>%
bind_rows() %>%
select(time_point,
day,
video_replicate,
file,
culture_ID,
id,
N_frames,
mean_area)
# Bind t0 with t1-t4
ds_individuals = rbind(ds_individuals_t0_elongated,
ds_individuals_t1_to_t4) %>%
left_join(ecosystems_info,
by = "culture_ID")
# Rename and select columns
ds_individuals = ds_individuals %>%
rename(ecosystem_size = patch_size,
ecosystem_size_volume = patch_size_volume) %>%
select(
disturbance,
disturbance_volume,
time_point,
day,
video_replicate,
culture_ID,
system_nr,
file,
eco_metaeco_type,
ecosystem_size,
ecosystem_size_volume,
metaecosystem,
metaecosystem_type,
mean_area,
N_frames
) %>%
rename(ecosystem_size_ml = ecosystem_size_volume,
ecosystem_type = eco_metaeco_type,
body_area_µm2 = mean_area)
# Rename and reorder levels
ds_individuals <- ds_individuals %>%
mutate(ecosystem_type = case_when(ecosystem_type == "S" ~ "Small unconnected",
ecosystem_type == "M" ~ "Medium unconnected",
ecosystem_type == "L" ~ "Large unconnected",
ecosystem_type == "S (S_S)" ~ "Small connected to small",
ecosystem_type == "S (S_L)" ~ "Small connected to large",
ecosystem_type == "M (M_M)" ~ "Medium connected to medium",
ecosystem_type == "L (S_L)" ~ "Large connected to small",
ecosystem_type == "L (L_L)" ~ "Large connected to large",
TRUE ~ ecosystem_type),
ecosystem_type = factor(ecosystem_type,
levels = ecosystem_types_ordered))
ds_individuals <- ds_individuals %>%
mutate(ecosystem_size = case_when(ecosystem_size == "S" ~ "Small",
ecosystem_size == "M" ~ "Medium",
ecosystem_size == "L" ~ "Large",
TRUE ~ ecosystem_type),
ecosystem_size = factor(ecosystem_size,
levels = "Small",
"Medium",
"Large"))
ds_individuals <- ds_individuals %>%
mutate(size_connected_ecosystem = case_when(ecosystem_type == "Small connected to small" ~ "Small",
ecosystem_type == "Small connected to large" ~ "Large",
ecosystem_type == "Medium connected to medium" ~ "Medium",
ecosystem_type == "Large connected to large" ~ "Large",
ecosystem_type == "Large connected to small" ~ "Small",
TRUE ~ NA_character_))
# Take off problematic videos
ds_individuals_before_taking_off_videos = ds_individuals
ds_individuals = ds_individuals %>%
filter(!(time_point %in% videos_to_take_off$time_point & file %in% videos_to_take_off$file))
diff = setdiff(ds_individuals_before_taking_off_videos, ds_individuals)
expect_equal(nrow(videos_to_take_off),
nrow(expand.grid(diff$culture_ID, diff$time_point, diff$file) %>% unique()))
# Take off problematic cultures
ds_individuals_before_taking_off_cultures = ds_individuals
ds_individuals = ds_individuals %>%
filter(!culture_ID %in% ecosystems_to_take_off)
expect_equal(setdiff(ds_individuals_before_taking_off_cultures,
ds_individuals) %>%
pull(culture_ID) %>%
unique(),
ecosystems_to_take_off)
ds_ecosystems)In this dataset (ds_ecosystems) each row represents a
ecosystem at a time point. I use the data from the 40 threshold analysis
for Ble, Cep, Spi and the data from the 13 threshold analysis for all
the other protists (Col, Eup, Lox, Pau, Pca, Spi te, Tet).
# Import & bind t0 datasets.
ds_ecosystems_t0 = read.csv(here("2_data",
"ecosystems_13_threshold",
"t0.csv")) %>%
mutate(time_point = as.numeric(str_extract(time_point, "\\d+")),
day = 0,
video_replicate = file) %>%
select(time_point,
day,
video_replicate,
file,
bioarea_per_volume,
indiv_per_volume)
species_ID_13_threshold_t0 = read.csv(here("2_data",
"species_ID_13_threshold",
paste0("t0.csv"))) %>%
rename(Ble_indiv_per_volume = Ble,
Cep_indiv_per_volume = Cep,
Col_indiv_per_volume = Col,
Eug_indiv_per_volume = Eug,
Eup_indiv_per_volume = Eup,
Lox_indiv_per_volume = Lox,
Pau_indiv_per_volume = Pau,
Pca_indiv_per_volume = Pca,
Spi_indiv_per_volume = Spi,
Spi_te_indiv_per_volume = Spi_te,
Tet_indiv_per_volume = Tet) %>%
select(file,
all_of(species_IDD_with_13_threshold_indiv_per_volume))
species_ID_40_threshold_t0 = read.csv(here("2_data",
"species_ID_40_threshold",
paste0("t0.csv"))) %>%
rename(Ble_indiv_per_volume = Ble,
Cep_indiv_per_volume = Cep,
Col_indiv_per_volume = Col,
Eug_indiv_per_volume = Eug,
Eup_indiv_per_volume = Eup,
Lox_indiv_per_volume = Lox,
Pau_indiv_per_volume = Pau,
Pca_indiv_per_volume = Pca,
Spi_indiv_per_volume = Spi,
Spi_te_indiv_per_volume = Spi_te,
Tet_indiv_per_volume = Tet) %>%
select(file,
all_of(species_IDD_with_40_threshold_indiv_per_volume))
ds_ecosystems_t0 = ds_ecosystems_t0 %>%
left_join(species_ID_13_threshold_t0,
by = "file") %>%
left_join(species_ID_40_threshold_t0,
by = "file") %>%
mutate(file = as.numeric(str_extract(file, "\\d+")))
# Elongate t0 dataset.
ds_ecosystems_t0_elongated <- list()
for (video_i in 1 : n_videos_taken_t0) {
single_video = ds_ecosystems_t0 %>%
filter(file == video_i)
ds_ecosystems_t0_elongated[[video_i]] = ecosystems_info %>%
mutate(time_point = 0,
day = 0,
file = single_video$file,
video_replicate = single_video$video_replicate,
bioarea_per_volume = single_video$bioarea_per_volume,
indiv_per_volume = single_video$indiv_per_volume,
Ble_indiv_per_volume = single_video$Ble_indiv_per_volume,
Cep_indiv_per_volume = single_video$Cep_indiv_per_volume,
Col_indiv_per_volume = single_video$Col_indiv_per_volume,
Eug_indiv_per_volume = single_video$Eug_indiv_per_volume,
Eup_indiv_per_volume = single_video$Eup_indiv_per_volume,
Lox_indiv_per_volume = single_video$Lox_indiv_per_volume,
Pau_indiv_per_volume = single_video$Pau_indiv_per_volume,
Pca_indiv_per_volume = single_video$Pca_indiv_per_volume,
Spi_indiv_per_volume = single_video$Spi_indiv_per_volume,
Spi_te_indiv_per_volume = single_video$Spi_te_indiv_per_volume,
Tet_indiv_per_volume = single_video$Tet_indiv_per_volume)
}
ds_ecosystems_t0_elongated = ds_ecosystems_t0_elongated %>%
bind_rows()
# Clean the columns of t0
ds_ecosystems_t0 = ds_ecosystems_t0_elongated %>%
select(file,
time_point,
day,
culture_ID,
video_replicate,
bioarea_per_volume,
indiv_per_volume,
all_of(protist_species_indiv_per_volume))
expect_equal(nrow(ds_ecosystems_t0),
sum(n_videos_taken_t0 * n_cultures))
# Import and bind t1-t4
ds_ecosystems_t1_to_t4 = NULL
for (time_point_i in time_points_without_t0) {
species_ID_13_threshold = read.csv(here("2_data",
"species_ID_13_threshold",
paste0("t", time_point_i, ".csv"))) %>%
rename(Ble_indiv_per_volume = Ble,
Cep_indiv_per_volume = Cep,
Col_indiv_per_volume = Col,
Eug_indiv_per_volume = Eug,
Eup_indiv_per_volume = Eup,
Lox_indiv_per_volume = Lox,
Pau_indiv_per_volume = Pau,
Pca_indiv_per_volume = Pca,
Spi_indiv_per_volume = Spi,
Spi_te_indiv_per_volume = Spi_te,
Tet_indiv_per_volume = Tet) %>%
select(file,
all_of(species_IDD_with_13_threshold_indiv_per_volume))
species_ID_40_threshold = read.csv(here("2_data",
"species_ID_40_threshold",
paste0("t", time_point_i, ".csv"))) %>%
rename(Ble_indiv_per_volume = Ble,
Cep_indiv_per_volume = Cep,
Col_indiv_per_volume = Col,
Eug_indiv_per_volume = Eug,
Eup_indiv_per_volume = Eup,
Lox_indiv_per_volume = Lox,
Pau_indiv_per_volume = Pau,
Pca_indiv_per_volume = Pca,
Spi_indiv_per_volume = Spi,
Spi_te_indiv_per_volume = Spi_te,
Tet_indiv_per_volume = Tet) %>%
select(file,
all_of(species_IDD_with_40_threshold_indiv_per_volume))
ds_ecosystems_t1_to_t4[[time_point_i]] = read.csv(here("2_data",
"ecosystems_13_threshold",
paste0("t", time_point_i, ".csv"))) %>%
arrange(file) %>%
mutate(video_replicate = rep(1 : time_point_day$video_replicates[time_point_i+1],
each = n_cultures),
day = time_point_day$day[time_point_day$time_point == time_point_i]) %>%
select(file,
time_point,
day,
video_replicate,
file,
culture_ID,
bioarea_per_volume,
indiv_per_volume)
ds_ecosystems_t1_to_t4[[time_point_i]] = ds_ecosystems_t1_to_t4[[time_point_i]] %>%
left_join(species_ID_13_threshold,
by = "file") %>%
left_join(species_ID_40_threshold,
by = "file")
}
ds_ecosystems_t1_to_t4 = ds_ecosystems_t1_to_t4 %>%
bind_rows()
# Bind t0 with t1-t4
ds_ecosystems = rbind(ds_ecosystems_t0,
ds_ecosystems_t1_to_t4) %>%
left_join(ecosystems_info,
by = "culture_ID")
expect_equal(nrow(ds_ecosystems),
sum(sum(time_point_day$video_replicates) * n_cultures))
# Reorder and rename columns
ds_ecosystems = ds_ecosystems %>%
rename(ecosystem_size = patch_size,
ecosystem_size_ml = patch_size_volume) %>%
select(file,
time_point,
day,
disturbance,
culture_ID,
system_nr,
eco_metaeco_type,
ecosystem_size,
ecosystem_size_ml,
metaecosystem,
metaecosystem_type,
video_replicate,
bioarea_per_volume,
indiv_per_volume,
all_of(protist_species_indiv_per_volume)) %>%
rename(bioarea_µm2_per_μL = bioarea_per_volume) %>%
rename_all( ~ gsub("volume", "μL", .))
# Rename and reorder levels
ds_ecosystems <- ds_ecosystems %>%
mutate(ecosystem_size = case_when(ecosystem_size == "S" ~ "Small",
ecosystem_size == "M" ~ "Medium",
ecosystem_size == "L" ~ "Large",
TRUE ~ ecosystem_size),
connection = case_when(eco_metaeco_type == "S" ~ "unconnected",
eco_metaeco_type == "M" ~ "unconnected",
eco_metaeco_type == "L" ~ "unconnected",
eco_metaeco_type == "S (S_S)" ~ "connected to small",
eco_metaeco_type == "S (S_L)" ~ "connected to large",
eco_metaeco_type == "M (M_M)" ~ "connected to medium",
eco_metaeco_type == "L (S_L)" ~ "connected to small",
eco_metaeco_type == "L (L_L)" ~ "connected to large"),
ecosystem_type = paste(ecosystem_size, connection),
metaecosystem_type = case_when(metaecosystem_type == "S_S" ~ "Small-Small",
metaecosystem_type == "M_M" ~ "Medium-Medium",
metaecosystem_type == "L_L" ~ "Large-Large",
metaecosystem_type == "S_L" ~ "Small-Large",
TRUE ~ metaecosystem_type),
time_point = as.numeric(str_extract(time_point, "\\d+")),
file = as.numeric(str_extract(file, "\\d+")))
# Change units of measurments to ml
ds_ecosystems = ds_ecosystems %>%
mutate(bioarea_µm2_per_ml = bioarea_µm2_per_μL * 10^3,
bioarea_mm2_per_ml = bioarea_µm2_per_ml * 10^(-6),
Ble_indiv_per_ml = Ble_indiv_per_μL * 10^3,
Cep_indiv_per_ml = Cep_indiv_per_μL * 10^3,
Col_indiv_per_ml = Col_indiv_per_μL * 10^3,
Eug_indiv_per_ml = Eug_indiv_per_μL * 10^3,
Eup_indiv_per_ml = Eup_indiv_per_μL * 10^3,
Lox_indiv_per_ml = Lox_indiv_per_μL * 10^3,
Pau_indiv_per_ml = Pau_indiv_per_μL * 10^3,
Pca_indiv_per_ml = Pca_indiv_per_μL * 10^3,
Spi_indiv_per_ml = Spi_indiv_per_μL * 10^3,
Spi_te_indiv_per_ml = Spi_te_indiv_per_μL * 10^3,
Tet_indiv_per_ml = Tet_indiv_per_μL * 10^3)
# Take off problematic videos
ds_ecosystems_before_taking_off_videos = ds_ecosystems
ds_ecosystems = ds_ecosystems %>%
filter(!(time_point %in% videos_to_take_off$time_point & file %in% videos_to_take_off$file))
diff = setdiff(ds_ecosystems_before_taking_off_videos, ds_ecosystems)
expect_equal(nrow(videos_to_take_off),
nrow(expand.grid(diff$culture_ID, diff$time_point, diff$file) %>% unique()))
# Take off problematic cultures
ds_ecosystems_before_taking_off_cultures = ds_ecosystems
ds_ecosystems = ds_ecosystems %>%
filter(!culture_ID %in% ecosystems_to_take_off)
expect_equal(setdiff(ds_ecosystems_before_taking_off_cultures,
ds_ecosystems) %>%
pull(culture_ID) %>%
unique(),
ecosystems_to_take_off)
# Average videos
ds_ecosystems = ds_ecosystems %>%
group_by(across(all_of(columns_ecosystems))) %>%
summarise(across(contains("_per_ml"), mean),
across(contains("_tot"), mean)) %>%
ungroup()
expect_equal(nrow(ds_ecosystems),
(n_cultures - length(ecosystems_to_take_off)) * length(time_points))
# Add connection and individuals
ds_ecosystems = ds_ecosystems %>%
mutate(indiv_per_ml = !!rlang::parse_expr(paste(protist_species_indiv_per_ml,
collapse = " + ")))
# Calculate total response variable for the whole ecosystem
ds_ecosystems = ds_ecosystems %>%
mutate(bioarea_tot_mm2 = bioarea_mm2_per_ml * ecosystem_size_ml,
indiv_tot = indiv_per_ml * ecosystem_size_ml,
Ble_tot_indiv = Ble_indiv_per_ml * ecosystem_size_ml,
Cep_tot_indiv = Cep_indiv_per_ml * ecosystem_size_ml,
Col_tot_indiv = Col_indiv_per_ml * ecosystem_size_ml,
Eug_tot_indiv = Eug_indiv_per_ml * ecosystem_size_ml,
Eup_tot_indiv = Eup_indiv_per_ml * ecosystem_size_ml,
Lox_tot_indiv = Lox_indiv_per_ml * ecosystem_size_ml,
Pau_tot_indiv = Pau_indiv_per_ml * ecosystem_size_ml,
Pca_tot_indiv = Pca_indiv_per_ml * ecosystem_size_ml,
Spi_tot_indiv = Spi_indiv_per_ml * ecosystem_size_ml,
Spi_te_tot_indiv = Spi_te_indiv_per_ml * ecosystem_size_ml,
Tet_tot_indiv = Tet_indiv_per_ml * ecosystem_size_ml)
# Calculate species dominance
ds_ecosystems = ds_ecosystems %>%
mutate(across(.cols = all_of(protist_species_indiv_per_ml),
.fns = list(dominance = ~ (. / indiv_per_ml) * 100),
.names = "{col}_dominance"))
expect_equal(unique(ds_ecosystems$Ble_indiv_per_ml_dominance[ds_ecosystems$indiv_per_ml == 0]), NaN)
if (FALSE %in% unique((ds_ecosystems$Ble_indiv_per_ml/ds_ecosystems$indiv_per_ml) *100 == ds_ecosystems$Ble_indiv_per_ml_dominance)) stop()
# Calculate alpha diversity (Shannon, Simpson, Inverse Simpson, Evenness)
n_rows_ds_ecosystems_before_calculating_alpha = nrow(ds_ecosystems)
ds_ecosystems = calculate.alpha.diversity()
expect_equal(max(ds_ecosystems$species_richness),
length(protist_species))
expect_equal(nrow(ds_ecosystems),
n_rows_ds_ecosystems_before_calculating_alpha)
# Calculate median body size
n_rows_ds_ecosystems_before_median_size = nrow(ds_ecosystems)
ds_median_body_size = ds_individuals %>%
group_by(time_point,
culture_ID,
file) %>%
summarise(median_body_area_µm2 = median(body_area_µm2)) %>%
group_by(time_point,
culture_ID) %>%
summarise(median_body_area_µm2 = mean(median_body_area_µm2))
expect_true(nrow(ds_median_body_size) <= nrow(ds_ecosystems)) #Ds median body size could be less because some cultures might be crashed and not have any individual.
ds_ecosystems_before_full_join = ds_ecosystems
ds_ecosystems = full_join(ds_ecosystems, ds_median_body_size)
expect_equal(nrow(ds_ecosystems),
n_rows_ds_ecosystems_before_median_size)
# Calculate auto/heterotrophic ratio
ds_ecosystems = ds_ecosystems %>%
mutate(auto_hetero_ratio = (Eug_indiv_per_ml + Eup_indiv_per_ml) /
(Ble_indiv_per_ml +
Cep_indiv_per_ml +
Col_indiv_per_ml +
Lox_indiv_per_ml +
Pau_indiv_per_ml +
Pca_indiv_per_ml +
Spi_indiv_per_ml +
Spi_te_indiv_per_ml +
Tet_indiv_per_ml))
# Add evaporation rates
ds_for_evaporation = read.csv(here("2_data", "water_addition.csv")) %>%
pivot_longer(cols = starts_with("water_add_after_t"),
names_to = "time_point",
values_to = "water_addition_ml") %>%
mutate(time_point = as.double(str_extract(time_point, "\\d+")) + 1)
ds_ecosystems = ds_ecosystems %>%
left_join(ds_for_evaporation)
ds_ecosystems_effect_size)In this dataset (ds_ecosystems_effect_size) each row
represents a treatment at a time point. It contains the effect size of
the connection of a ecosystem (connected vs unconnected).
# Calculate the mean & sd of response variables for each treatment/control at each time point
ds_ecosystems_effect_size = NULL
variable_nr = 0
for (variable_i in variables_ecosystems) {
variable_nr = variable_nr + 1
ds_ecosystems_effect_size[[variable_nr]] = ds_ecosystems %>%
filter(time_point >= 1,
!is.na(!!sym(variable_i))) %>%
group_by(across(all_of(columns_ecosystems[columns_ecosystems != "culture_ID" &
columns_ecosystems != "system_nr"]))) %>%
summarise(across(all_of(variable_i),
list(mean = mean,
sd = sd)),
sample_size = n()) %>%
rename_with( ~ paste0(variable_i, "_sample_size"),
matches("sample_size"))
}
ds_ecosystems_effect_size <- reduce(ds_ecosystems_effect_size,
full_join,
by = columns_ecosystems[columns_ecosystems != "culture_ID" & columns_ecosystems != "system_nr"])
expect_equal(nrow(ds_ecosystems_effect_size),
n_ecosystem_types * (n_time_points-1) * n_disturbance_levels)
# Calculate the effect size (Hedge's d) for each treatment at each time point
for (variable_i in variables_ecosystems) {
ds_ecosystems_effect_size <- ds_ecosystems_effect_size %>%
mutate(!!paste0(variable_i, "_d") := NA,
!!paste0(variable_i, "_d_upper") := NA,
!!paste0(variable_i, "_d_lower") := NA)
}
row_i = 0
for (treatment_selected in treatments_and_controls$treatment) {
for (time_point_selected in time_points) {
row_i = row_i + 1
control_input = treatments_and_controls$control[treatments_and_controls$treatment == treatment_selected]
treatment_row = ds_ecosystems_effect_size %>%
filter(ecosystem_type == treatment_selected,
time_point == time_point_selected)
control_row = ds_ecosystems_effect_size %>%
filter(ecosystem_type == control_input,
time_point == time_point_selected)
for (response_variable in variables_ecosystems) {
hedges_d = calculate.hedges_d(treatment_row[[paste0(response_variable, "_mean")]],
treatment_row[[paste0(response_variable, "_sd")]],
treatment_row[[paste0(response_variable, "_sample_size")]],
control_row[[paste0(response_variable, "_mean")]],
control_row[[paste0(response_variable, "_sd")]],
control_row[[paste0(response_variable, "_sample_size")]])
ds_ecosystems_effect_size[[paste0(response_variable, "_d")]][
ds_ecosystems_effect_size$ecosystem_type == treatment_selected &
ds_ecosystems_effect_size$time_point == time_point_selected] =
hedges_d$d
ds_ecosystems_effect_size[[paste0(response_variable, "_d_upper")]][
ds_ecosystems_effect_size$ecosystem_type == treatment_selected &
ds_ecosystems_effect_size$time_point == time_point_selected] =
hedges_d$upper_CI
ds_ecosystems_effect_size[[paste0(response_variable, "_d_lower")]][
ds_ecosystems_effect_size$ecosystem_type == treatment_selected &
ds_ecosystems_effect_size$time_point == time_point_selected] =
hedges_d$lower_CI
}
}
}
expect_equal(nrow(ds_ecosystems_effect_size),
n_ecosystem_types * (n_time_points-1) * n_disturbance_levels)
ds_metaecosystems)In this dataset (ds_metaecosystems) each row represents
a meta-ecosystem or a two-ecosystem unconnected system at a time
point.
# --- Find the IDs of unconnected ecosystems --- #
ID_unconnected_S_low = ds_ecosystems %>%
filter(ecosystem_type == "Small unconnected",
disturbance == "low") %>%
pull(culture_ID) %>%
unique()
ID_unconnected_M_low = ds_ecosystems %>%
filter(ecosystem_type == "Medium unconnected",
disturbance == "low") %>%
pull(culture_ID) %>%
unique()
ID_unconnected_L_low = ds_ecosystems %>%
filter(ecosystem_type == "Large unconnected",
disturbance == "low") %>%
pull(culture_ID) %>%
unique()
ID_unconnected_S_high = ds_ecosystems %>%
filter(ecosystem_type == "Small unconnected",
disturbance == "high") %>%
pull(culture_ID) %>%
unique()
ID_unconnected_M_high = ds_ecosystems %>%
filter(ecosystem_type == "Medium unconnected",
disturbance == "high") %>%
pull(culture_ID) %>%
unique()
ID_unconnected_L_high = ds_ecosystems %>%
filter(ecosystem_type == "Large unconnected",
disturbance == "high") %>%
pull(culture_ID) %>%
unique()
# --- Find combinations of ecosystems to create unconnected meta-ecosystems --- #
combinations_S_and_L_low = crossing(ID_unconnected_S_low,
ID_unconnected_L_low) %>%
mutate(disturbance = "low",
metaecosystem_type = "Small-Large",
connection = "unconnected") %>%
rename(ID_first_ecosystem = ID_unconnected_S_low,
ID_second_ecosystem = ID_unconnected_L_low) %>%
select(disturbance,
metaecosystem_type,
connection,
ID_first_ecosystem,
ID_second_ecosystem)
combinations_S_and_L_high = crossing(ID_unconnected_S_high,
ID_unconnected_L_high) %>%
mutate(disturbance = "high",
metaecosystem_type = "Small-Large",
connection = "unconnected") %>%
rename(ID_first_ecosystem = ID_unconnected_S_high,
ID_second_ecosystem = ID_unconnected_L_high) %>%
select(disturbance,
metaecosystem_type,
connection,
ID_first_ecosystem,
ID_second_ecosystem)
combinations_M_and_M_low = combinat::combn(ID_unconnected_M_low,
m = 2) %>%
t() %>%
as.data.frame() %>%
rename(ID_first_ecosystem = V1,
ID_second_ecosystem = V2) %>%
mutate(disturbance = "low",
metaecosystem_type = "Medium-Medium",
connection = "unconnected") %>%
select(disturbance,
metaecosystem_type,
connection,
ID_first_ecosystem,
ID_second_ecosystem)
combinations_M_and_M_high = combinat::combn(ID_unconnected_M_high,
m = 2) %>%
t() %>%
as.data.frame() %>%
rename(ID_first_ecosystem = V1,
ID_second_ecosystem = V2) %>%
mutate(disturbance = "high",
metaecosystem_type = "Medium-Medium",
connection = "unconnected") %>%
select(disturbance,
metaecosystem_type,
connection,
ID_first_ecosystem,
ID_second_ecosystem)
# --- Bind ecosystem combinations --- #
combinations_unconnected_metaeco = rbind(combinations_S_and_L_low,
combinations_S_and_L_high,
combinations_M_and_M_low,
combinations_M_and_M_high) %>%
mutate(system_nr = 1001:(1000 + nrow(.))) %>%
select(system_nr,
disturbance,
metaecosystem_type,
connection,
ID_first_ecosystem,
ID_second_ecosystem)
# --- Find combinations of ecosystems to create connected meta-ecosystems --- #
combinations_connected_metaeco = ds_ecosystems %>%
filter(time_point == 0,
metaecosystem == "yes") %>%
select(system_nr,
disturbance,
metaecosystem_type,
culture_ID) %>%
group_by(system_nr,
disturbance,
metaecosystem_type) %>%
summarise(ID_first_ecosystem = (mean(culture_ID) - 0.5),
ID_second_ecosystem = (mean(culture_ID) + 0.5)) %>%
mutate(connection = "connected") %>%
as.data.frame()
# --- Bind combinations of ecosystems to create unconnected and connected meta-ecosystems --- #
ecosystem_combinations = rbind(combinations_unconnected_metaeco,
combinations_connected_metaeco) %>%
mutate(ecosystems_combined = paste0(ID_first_ecosystem, "|", ID_second_ecosystem))
n_ecosystems_combinations = nrow(ecosystem_combinations)
# --- Create sets for SL unconnected, where in each set a small and a large ecosystems are paired differently --- #
#I keep the small ecosystems on the same order and perform permutations on large ecosystems
SL_unconnected_sys_sets <- vector("list",
length(disturbance_levels))
for (disturbance_i in 1:length(disturbance_levels)) {
ID_small_ecosystems = ds_ecosystems %>%
filter(disturbance == disturbance_levels[disturbance_i],
ecosystem_type == "Small unconnected") %>%
pull(culture_ID) %>%
unique()
ID_large_ecosystems = ds_ecosystems %>%
filter(disturbance == disturbance_levels[disturbance_i],
ecosystem_type == "Large unconnected") %>%
pull(culture_ID) %>%
unique()
#Force small and large ecosystems vectors to have the same length
length_difference <- length(ID_small_ecosystems) - length(ID_large_ecosystems)
if (length_difference > 0) {
ID_large_ecosystems = c(ID_large_ecosystems,
rep("Patch taken off",
times = abs(length(ID_small_ecosystems) -
length(ID_large_ecosystems))))
} else if (length_difference < 0) {
ID_small_ecosystems = c(ID_small_ecosystems,
rep("Patch taken off",
times = abs(length(ID_large_ecosystems) -
length(ID_small_ecosystems))))
}
# Create dataframe
permutations_large = permn(ID_large_ecosystems)
SL_unconnected_sys_sets[[disturbance_i]] = data.frame(disturbance = disturbance_levels[disturbance_i],
metaecosystem_type = "Small-Large",
connection = "unconnected",
ID_first_ecosystem = rep(ID_small_ecosystems, times = length(permutations_large)),
ID_second_ecosystem = unlist(permutations_large),
set = rep(1 : length(permutations_large),
each = length(ID_small_ecosystems)))
expect_equal(nrow(SL_unconnected_sys_sets[[disturbance_i]]),
length(ID_small_ecosystems) * length(permutations_large))
SL_unconnected_sys_sets[[disturbance_i]] = SL_unconnected_sys_sets[[disturbance_i]] %>%
filter(!ID_first_ecosystem == "Patch taken off",
!ID_second_ecosystem == "Patch taken off") %>%
mutate(ID_first_ecosystem = as.double(ID_first_ecosystem),
ID_second_ecosystem = as.double(ID_second_ecosystem)) %>%
full_join(ecosystem_combinations %>%
filter(disturbance == disturbance_levels[disturbance_i],
metaecosystem_type == "Small-Large",
connection == "unconnected")) #Add system_nr & ecosystems_combined
}
SL_unconnected_sys_sets_before_binding = SL_unconnected_sys_sets
SL_unconnected_sys_sets = SL_unconnected_sys_sets %>%
bind_rows()
expect_equal(nrow(SL_unconnected_sys_sets),
nrow(SL_unconnected_sys_sets_before_binding[[1]]) + nrow(SL_unconnected_sys_sets_before_binding[[2]]))
expect_equal(length(SL_unconnected_sys_sets %>%
pull(system_nr) %>%
unique()),
length(ecosystem_combinations %>%
filter(metaecosystem_type == "Small-Large",
connection == "unconnected") %>%
pull(system_nr) %>%
unique()))
# --- Create sets for MM unconnected, where in each set two different medium ecosystems are paired--- #
#To do so, I ...
#Initialise MM_unconnected_sets. Assign 10^4 rows to each matrix so that we have enough rows not to run out of them when we try to assign values to them. Assign 4 columns which will include culture_ID of the first system, second culture_ID of the fist system, culture_ID of the second system, and second culture_ID of the second system.
MM_unconnected_sets = NULL
for(disturbance_i in 1:length(disturbance_levels)){
MM_unconnected_sets[[disturbance_i]] <- matrix(nrow = 10 ^ 4,
ncol = 4)
}
for (disturbance_i in 1:length(disturbance_levels)) {
ID_medium_ecosystems = ds_ecosystems %>%
filter(disturbance == disturbance_levels[disturbance_i],
ecosystem_type == "Medium unconnected") %>%
pull(culture_ID) %>%
unique()
MM_unconnected_systems = combn(ID_medium_ecosystems,
2) %>%
t()
matrix_row = 0
for (first_system_i in 1:nrow(MM_unconnected_systems)) {
#Find culture IDs of the first system (what's the first system?)
first_system = MM_unconnected_systems[first_system_i, ]
for (second_system_i in 1:nrow(MM_unconnected_systems)) {
#Find culture IDs of the second system (what's the second system?)
second_system = MM_unconnected_systems[second_system_i, ]
shared_elements_among_systems = intersect(first_system,
second_system)
if (length(shared_elements_among_systems) == 0) {
matrix_row = matrix_row + 1
#Make first and second system into a set
MM_unconnected_sets[[disturbance_i]][matrix_row,] = c(first_system,
second_system)
print(MM_unconnected_sets[[disturbance_i]][matrix_row,])
}
}
}
#Tidy the dataset with all the ecosystem combinations
MM_unconnected_sets[[disturbance_i]] = MM_unconnected_sets[[disturbance_i]] %>%
as.data.frame() %>%
drop_na()
expect_equal(MM_unconnected_sets[[disturbance_i]] %>%
filter(V1 == V2 | V1 == V3 | V1 == V4 | V2 == V3 | V2 == V4 | V3 == V4) %>%
nrow(),
0)
#Reorder the dataset with all the ecosystem combinations
MM_unconnected_sets_reordered = data.frame(ID_first_ecosystem = NA,
ID_second_ecosystem = NA,
set = NA)
for (set_input in 1:nrow(MM_unconnected_sets[[disturbance_i]])) {
MM_unconnected_sets_reordered = MM_unconnected_sets_reordered %>%
add_row(ID_first_ecosystem = MM_unconnected_sets[[disturbance_i]][set_input, 1],
ID_second_ecosystem = MM_unconnected_sets[[disturbance_i]][set_input, 2],
set = set_input) %>%
add_row(ID_first_ecosystem = MM_unconnected_sets[[disturbance_i]][set_input, 3],
ID_second_ecosystem = MM_unconnected_sets[[disturbance_i]][set_input, 4],
set = set_input)
}
#Add to a list
MM_unconnected_sets[[disturbance_i]] = MM_unconnected_sets_reordered %>%
drop_na() %>%
mutate(disturbance = disturbance_levels[disturbance_i],
metaecosystem_type = "Medium-Medium",
connection = "unconnected")
#Add system nr
ID_combinations_MM_unconnected = ecosystem_combinations %>%
filter(disturbance == disturbance_levels[disturbance_i],
metaecosystem_type == "Medium-Medium",
connection == "unconnected")
MM_unconnected_sets[[disturbance_i]] = full_join(MM_unconnected_sets[[disturbance_i]],
ID_combinations_MM_unconnected)
}
## [1] 6 7 8 9
## [1] 6 7 8 10
## [1] 6 7 9 10
## [1] 6 8 7 9
## [1] 6 8 7 10
## [1] 6 8 9 10
## [1] 6 9 7 8
## [1] 6 9 7 10
## [1] 6 9 8 10
## [1] 6 10 7 8
## [1] 6 10 7 9
## [1] 6 10 8 9
## [1] 7 8 6 9
## [1] 7 8 6 10
## [1] 7 8 9 10
## [1] 7 9 6 8
## [1] 7 9 6 10
## [1] 7 9 8 10
## [1] 7 10 6 8
## [1] 7 10 6 9
## [1] 7 10 8 9
## [1] 8 9 6 7
## [1] 8 9 6 10
## [1] 8 9 7 10
## [1] 8 10 6 7
## [1] 8 10 6 9
## [1] 8 10 7 9
## [1] 9 10 6 7
## [1] 9 10 6 8
## [1] 9 10 7 8
## [1] 61 62 63 64
## [1] 61 62 63 65
## [1] 61 62 64 65
## [1] 61 63 62 64
## [1] 61 63 62 65
## [1] 61 63 64 65
## [1] 61 64 62 63
## [1] 61 64 62 65
## [1] 61 64 63 65
## [1] 61 65 62 63
## [1] 61 65 62 64
## [1] 61 65 63 64
## [1] 62 63 61 64
## [1] 62 63 61 65
## [1] 62 63 64 65
## [1] 62 64 61 63
## [1] 62 64 61 65
## [1] 62 64 63 65
## [1] 62 65 61 63
## [1] 62 65 61 64
## [1] 62 65 63 64
## [1] 63 64 61 62
## [1] 63 64 61 65
## [1] 63 64 62 65
## [1] 63 65 61 62
## [1] 63 65 61 64
## [1] 63 65 62 64
## [1] 64 65 61 62
## [1] 64 65 61 63
## [1] 64 65 62 63
#Bind all sets of MM unconnected
MM_unconnected_sets = MM_unconnected_sets %>%
bind_rows()
expect_equal(length(MM_unconnected_sets %>%
pull(system_nr) %>%
unique()),
length(ecosystem_combinations %>%
filter(metaecosystem_type == "Medium-Medium",
connection == "unconnected") %>%
pull(system_nr) %>%
unique()))
# --- Bind SL and MM unconnected systems --- #
unconnected_combinations_sets = rbind(SL_unconnected_sys_sets,
MM_unconnected_sets) %>%
select(disturbance,
metaecosystem_type,
connection,
set,
system_nr,
ID_first_ecosystem,
ID_second_ecosystem)
Each row is a meta-ecosystem.
It contains also “fake” meta-ecosystems which I created from
unconnected ecosystems
(metaecosystem type = Small-Large unconnected &
metaecosystem type = Medium-Medium unconnected).
Warning appear after the following code, as:
# --- Compute meta-ecosystems for each time point --- #
ds_metaecosystems = NULL
row_i = 0
for (combination_i in 1:n_ecosystems_combinations) {
for (time_point_selected in time_points) {
row_i = row_i + 1
current_day = sampling_days[time_point_selected + 1]
current_system_nr = ecosystem_combinations[combination_i, ]$system_nr
current_combination = ecosystem_combinations[combination_i, ]$ecosystems_combined
current_disturbance = ecosystem_combinations[combination_i, ]$disturbance
current_metaeco_type = ecosystem_combinations[combination_i, ]$metaecosystem_type
current_connection = ecosystem_combinations[combination_i, ]$connection
current_IDs = c(ecosystem_combinations[combination_i, ]$ID_first_ecosystem,
ecosystem_combinations[combination_i, ]$ID_second_ecosystem)
if (current_system_nr %in% metaecosystems_to_take_off)
next
if (current_IDs[1] == current_IDs[2])
next
species_vector_two_ecosystems = ds_ecosystems %>%
filter(time_point == time_point_selected,
culture_ID %in% current_IDs) %>%
ungroup() %>%
select(all_of(protist_species_indiv_per_ml))
absence_presence_two_ecosystems <-
ifelse(species_vector_two_ecosystems > 0, 1, 0)
#Alpha diversity: Shannon (mean between the two ecosystems)
shannon_ecosystem_1 = diversity(species_vector_two_ecosystems[1, ], index = "shannon")
shannon_ecosystem_2 = diversity(species_vector_two_ecosystems[2, ], index = "shannon")
shannon_value = (shannon_ecosystem_1 + shannon_ecosystem_2) / 2
#Alpha diversity: Species richness (mean between the two ecosystems)
richness_ecosystem_1 = specnumber(species_vector_two_ecosystems[1, ])
richness_ecosystem_2 = specnumber(species_vector_two_ecosystems[2, ])
mean_richness_value = (richness_ecosystem_1 + richness_ecosystem_2) / 2
#Beta diversity: Jaccard
jaccard_index_value = vegdist(species_vector_two_ecosystems,
method = "jaccard") %>%
as.numeric()
#Beta diversity: Bray Curtis
bray_curtis_value = vegdist(species_vector_two_ecosystems,
method = "bray") %>%
as.numeric()
#Beta diversity: partitioning of beta diversity from Sorensen index into turnover (Simpson pair-wise dissimilarity) and nestedness (nestedness-fraction of Sorensen)
betapart_core_object = betapart.core(absence_presence_two_ecosystems)
beta_spatial_turnover_value = beta.pair(betapart_core_object)$beta.sim %>% as.double()
beta_nestedness_value = beta.pair(betapart_core_object)$beta.sne %>% as.double()
beta_total_value = beta.pair(betapart_core_object)$beta.sor %>% as.double()
#Gamma diversity: Meta-ecosystem richness
metaecosystem_richness_value = colSums(species_vector_two_ecosystems) %>%
specnumber()
#Put everything together
ds_metaecosystems[[row_i]] = ds_ecosystems %>%
filter(culture_ID %in% current_IDs,
time_point == time_point_selected) %>%
summarise(total_metaecosystem_bioarea_mm2 = sum(bioarea_tot_mm2),
total_metaecosystem_Ble_indiv = sum(Ble_tot_indiv),
total_metaecosystem_Cep_indiv = sum(Cep_tot_indiv),
total_metaecosystem_Col_indiv = sum(Col_tot_indiv),
total_metaecosystem_Eug_indiv = sum(Eug_tot_indiv),
total_metaecosystem_Eup_indiv = sum(Eup_tot_indiv),
total_metaecosystem_Lox_indiv = sum(Lox_tot_indiv),
total_metaecosystem_Pau_indiv = sum(Pau_tot_indiv),
total_metaecosystem_Pca_indiv = sum(Pca_tot_indiv),
total_metaecosystem_Spi_indiv = sum(Spi_tot_indiv),
total_metaecosystem_Spi_te_indiv = sum(Spi_te_tot_indiv),
total_metaecosystem_Tet_indiv = sum(Tet_tot_indiv),
total_water_addition_ml = sum(water_addition_ml)) %>%
mutate(system_nr = current_system_nr,
ecosystems_combined = current_combination,
metaecosystem_type = current_metaeco_type,
ecosystem_size_symmetry = case_when(metaecosystem_type == "Small-Large" ~ "asymmetric",
metaecosystem_type == "Medium-Medium" ~ "symmetric",
metaecosystem_type == "Small-Small" ~ "symmetric",
metaecosystem_type == "Large-Large" ~ "symmetric"),
connection = current_connection,
disturbance = current_disturbance,
time_point = time_point_selected,
day = current_day,
jaccard_index = jaccard_index_value,
bray_curtis = bray_curtis_value,
beta_spatial_turnover = beta_spatial_turnover_value,
beta_nestedness = beta_nestedness_value,
beta_total = beta_total_value,
metaecosystem_richness = metaecosystem_richness_value,
mean_shannon = shannon_value,
mean_richness = mean_richness_value) %>%
ungroup()
}
}
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): missing
## values in results
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): missing
## values in results
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): missing
## values in results
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): missing
## values in results
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
## Warning in vegdist(species_vector_two_ecosystems, method = "jaccard"): you have empty rows: their dissimilarities may be
## meaningless in method "jaccard"
## Warning in vegdist(species_vector_two_ecosystems, method = "bray"): you have empty rows: their dissimilarities may be
## meaningless in method "bray"
ds_metaecosystems = ds_metaecosystems %>%
bind_rows() %>%
as.data.frame() %>%
select(time_point,
day,
system_nr,
ecosystems_combined,
disturbance,
metaecosystem_type,
ecosystem_size_symmetry,
connection,
mean_shannon,
mean_richness,
jaccard_index,
bray_curtis,
beta_spatial_turnover,
beta_nestedness,
beta_total,
metaecosystem_richness,
total_metaecosystem_bioarea_mm2,
paste0("total_metaecosystem_", protist_species, "_indiv"),
total_water_addition_ml)
expect_equal(nrow(ds_metaecosystems),
n_time_points * n_ecosystems_combinations)
Here I’m filtering ecosystems to have only the ones with disturbance high.
ds_ecosystems_both_disturbances = ds_ecosystems
ds_metaecosystems_both_disturbances = ds_metaecosystems
#Filter data sets according to the global disturbance
ds_individuals = ds_individuals %>%
filter(disturbance == disturbance_global_selected)
ds_ecosystems = ds_ecosystems %>%
filter(disturbance == disturbance_global_selected)
ds_ecosystems_effect_size = ds_ecosystems_effect_size %>%
filter(disturbance == disturbance_global_selected)
ds_metaecosystems = ds_metaecosystems %>%
filter(disturbance == disturbance_global_selected)
ds_classes = ds_classes %>%
filter(disturbance == disturbance_global_selected)
ds_classes_effect_size = ds_classes_effect_size %>%
filter(disturbance == disturbance_global_selected)
metaecosystem_type_selected = c("Small-Small",
"Large-Large",
"Medium-Medium",
"Small-Large")
connection_selected = c("connected",
"unconnected")
response_variable_selected = "mean_shannon"
Here we want to look at how this meta-ecosystem variable changed across time by plotting its mean ± 95 confidence interval:
plot.metaecos.points(ds_metaecosystems,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
plot.metaecos.replicates(ds_metaecosystems,
metaecosystem_type_selected,
response_variable_selected)
response_variable_selected = "bray_curtis"
Here we want to look at how this meta-ecosystem variable changed across time by plotting its mean ± 95 confidence interval:
plot.metaecos.points(ds_metaecosystems,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
plot.metaecos.replicates(ds_metaecosystems,
metaecosystem_type_selected,
response_variable_selected)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_summary()`).
response_variable_selected = "metaecosystem_richness"
Here we want to look at how this meta-ecosystem variable changed across time by plotting its mean ± 95 confidence interval:
plot.metaecos.points(ds_metaecosystems,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
plot.metaecos.replicates(ds_metaecosystems,
metaecosystem_type_selected,
response_variable_selected)
response_variable_selected = "total_metaecosystem_bioarea_mm2"
Here we want to look at how this meta-ecosystem variable changed across time by plotting its mean ± 95 confidence interval:
plot.metaecos.points(ds_metaecosystems,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
plot.metaecos.replicates(ds_metaecosystems,
metaecosystem_type_selected,
response_variable_selected)
response_variable_selected = "mean_shannon"
metaecosystem_type_selected = c("Medium-Medium",
"Small-Large")
Here we want to look at how this meta-ecosystem variable changed across time by plotting its mean ± 95 confidence interval:
plot.metaecos.points(ds_metaecosystems,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
plot.metaecos.replicates(ds_metaecosystems,
metaecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among meta-ecosystems. To make it easier to interpret differences, we decided to construct a model for each comparisons we are interested in, which are: SL (connected vs unconnected) and MM (connected vs unconnected).
comparison_type = "all"
metaecosystem_type_selected = c("Small-Large")
Our first step in the data analysis involves filtering the data to isolate the relevant data. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure we filtered data the right way.
# --- FILTER DATA --- #
filtered_data = ds_metaecosystems %>%
filter(time_point %in% time_points_model,
metaecosystem_type %in% metaecosystem_type_selected,
!is.na(!!sym("total_water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.metaecos.points(filtered_data,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same meta-ecosystem on multiple occasions, we can develop mixed effect models to examine how the connection influenced this meta-ecosystem variable. To study the effects of connection we compare two models to a null model using ANOVA: a full model and a reduced model. In all models, we treat system nr as having a random effect on how the slope and intercept of the relationship between response variable and time, with the slope and intercept being correlated (Bates et al. 2015). We also include the total water that was added due to evaporation in the microwave and the time point before the first disturbance (baseline). In the syntax of lmer4 the three models look this this:
Full model = response_variable ~connection * scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Reduced model = response_variable ~connection + scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Null model = response_variable ~scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Unconnected meta-ecosystems are made of paired unconnected
ecosystems, which are paired randomly. However, how to pair unconnected
ecosystems can be done in multiple ways, as unconnected ecosystems did
not interact and therefore any combination between ecosystems would be
arbitrary. To make sure that the random combination we selected did not
bias our results, we run all the possible combinations of ecosystems
constituting unconnected meta-ecosystems. The ecosystem combinations are
into the objects unconnected_combinations_sets (Data >
Meta-ecosystems). We therefore compute a p-value for each unconnected
ecosystems combination, creating a p-value distribution. We keep as
p-value of the comparison the median of such distributions.
# --- ADD BASELINES --- #
baselines = ds_metaecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(system_nr,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PREPARE TO COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
unconnected_combinations_sets_filtered = unconnected_combinations_sets %>%
filter(disturbance == disturbance_global_selected,
metaecosystem_type %in% metaecosystem_type_selected)
n_sets = unconnected_combinations_sets_filtered %>%
pull(set) %>%
max()
iterated_results_table = data.frame(Response = as.character(NA),
Levels = as.character(NA),
ΔAIC_full = NA,
p_full = NA,
ΔR2_full = NA,
ΔAIC_fix = NA,
p_fix = NA,
ΔR2_fix = NA,
combination_set = NA,
system_nr_unconnected_systems = as.character(NA)) %>%
slice(-1)
# --- COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
full_model_res_vs_fit = NULL
reduced_model_res_vs_fit = NULL
null_model_res_vs_fit = NULL
for (set_i in 1:n_sets) {
# Filter the data to contain all the connected meta-ecosystems and only a subset of unconnected meta-ecosystems
system_nr_unconnected_systems_input = unconnected_combinations_sets_filtered %>%
filter(metaecosystem_type %in% metaecosystem_type_selected,
connection == "unconnected",
set == set_i) %>%
pull(system_nr)
filtered_data_2 = filtered_data %>%
filter(connection == "connected" |
(connection == "unconnected" &
system_nr %in% system_nr_unconnected_systems_input))
# Construct models
full_model = try.different.optimizer.full.model()
reduced_model = try.different.optimizer.reduced.model()
null_model = try.different.optimizer.null.model()
# If all the optimisers fail, move on to the next iteration
if (is.null(full_model) || is.null(reduced_model) || is.null(null_model)) {
cat("This model could not be fitted with any optimiser. The unconnected meta-ecosystems in this iteration were:",
system_nr_unconnected_systems_input,
"\n")
next
}
if(plot_model_residuals_metaecos == TRUE){
# Plot residuals - full model
print(qqnorm(resid(full_model))); print(qqline(resid(full_model)))
#full_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, full_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(full_model),
residuals = resid(full_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_full_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - reduced model
print(qqnorm(resid(reduced_model))); print(qqline(resid(reduced_model)))
#reduced_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, reduced_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(reduced_model),
residuals = resid(reduced_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_reduced_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - null model
print(qqnorm(resid(null_model))); print(qqline(resid(null_model)))
#null_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, null_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(null_model),
residuals = resid(null_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_null_model.png")),
plot = plot,
width = 8,
height = 6)
}
# Give model statistics
model_stats_full = compute.model.stats(full_model,
null_model,
"mixed_model")
model_stats_reduced = compute.model.stats(reduced_model,
null_model,
"mixed_model")
# Save model statistics
iterated_results_table = fill.results.table(iterated_results_table,
response_variable_selected,
metaecosystem_type_selected,
model_stats_full,
model_stats_reduced)
iterated_results_table$set[nrow(iterated_results_table)] = set_i
iterated_results_table$system_nr_unconnected_systems[nrow(iterated_results_table)] =
paste(system_nr_unconnected_systems_input, collapse = " ")
}
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: nlminbwrap "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
Full vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_full = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_full),
p_value = median(iterated_results_table$p_full),
R2 = NA)
model_stats_full %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 -3.5 0.024 ** moderate
# --- FULL VS NULL MODEL - SHOW ΔAIC & P VALUE DISTRIBUTIONS --- #
hist(iterated_results_table$ΔAIC_full, main = "Distribution of ΔAIC of the full model.")
hist(iterated_results_table$p_full, main = "Distribution of p-values of the full model.")
# --- FULL VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_full) %>%
arrange(ΔAIC_full)
## system_nr_unconnected_systems ΔAIC_full
## 1 1030 1033 1039 1041 -7.5
## 2 1030 1032 1039 1041 -7.0
## 3 1029 1033 1040 1041 -6.8
## 4 1030 1031 1038 1044 -6.7
## 5 1028 1035 1039 1041 -6.7
## 6 1030 1032 1036 1044 -6.7
## 7 1030 1033 1036 1044 -6.6
## 8 1030 1034 1038 1041 -6.6
## 9 1028 1035 1036 1044 -6.4
## 10 1029 1035 1038 1041 -6.4
## 11 1026 1032 1039 1045 -6.3
## 12 1029 1032 1036 1045 -6.3
## 13 1027 1035 1039 1041 -6.3
## 14 1026 1035 1038 1044 -6.2
## 15 1028 1031 1040 1044 -6.1
## 16 1027 1035 1036 1044 -6.1
## 17 1028 1034 1040 1041 -6.0
## 18 1029 1032 1040 1041 -6.0
## 19 1027 1031 1039 1045 -6.0
## 20 1029 1031 1038 1045 -5.9
## 21 1026 1033 1040 1044 -5.9
## 22 1028 1031 1039 1045 -5.9
## 23 1026 1032 1040 1044 -5.8
## 24 1028 1034 1036 1045 -5.8
## 25 1027 1031 1040 1044 -5.8
## 26 1030 1031 1037 1044 -5.7
## 27 1026 1034 1038 1045 -5.6
## 28 1029 1033 1036 1045 -5.6
## 29 1027 1034 1036 1045 -5.6
## 30 1026 1035 1037 1044 -5.5
## 31 1029 1035 1037 1041 -5.5
## 32 1030 1031 1039 1043 -5.4
## 33 1026 1033 1039 1045 -5.4
## 34 1027 1034 1040 1041 -5.4
## 35 1029 1031 1037 1045 -5.2
## 36 1029 1031 1040 1043 -5.2
## 37 1030 1034 1036 1043 -5.0
## 38 1030 1034 1037 1041 -5.0
## 39 1029 1035 1036 1043 -4.9
## 40 1026 1035 1039 1043 -4.9
## 41 1026 1034 1037 1045 -4.8
## 42 1026 1034 1040 1043 -4.7
## 43 1028 1032 1039 1041 -4.5
## 44 1028 1032 1036 1044 -4.4
## 45 1030 1032 1038 1041 -4.3
## 46 1026 1032 1038 1044 -4.2
## 47 1027 1031 1038 1044 -4.2
## 48 1030 1032 1038 1044 -4.1
## 49 1029 1032 1038 1041 -4.1
## 50 1028 1031 1037 1044 -4.0
## 51 1027 1031 1039 1043 -3.9
## 52 1028 1032 1036 1045 -3.8
## 53 1027 1031 1038 1045 -3.8
## 54 1026 1032 1038 1045 -3.7
## 55 1027 1035 1038 1044 -3.6
## 56 1027 1034 1038 1041 -3.6
## 57 1029 1032 1038 1045 -3.6
## 58 1026 1032 1039 1043 -3.5
## 59 1030 1031 1039 1042 -3.5
## 60 1029 1031 1037 1043 -3.5
## 61 1028 1031 1037 1045 -3.5
## 62 1028 1034 1037 1041 -3.5
## 63 1028 1032 1039 1045 -3.5
## 64 1027 1035 1038 1041 -3.5
## 65 1027 1034 1038 1045 -3.5
## 66 1027 1031 1040 1043 -3.5
## 67 1028 1032 1040 1041 -3.4
## 68 1027 1033 1039 1041 -3.4
## 69 1026 1035 1039 1042 -3.3
## 70 1029 1033 1037 1041 -3.3
## 71 1028 1035 1037 1041 -3.3
## 72 1029 1032 1036 1043 -3.3
## 73 1030 1031 1037 1043 -3.2
## 74 1029 1035 1036 1042 -3.2
## 75 1029 1031 1040 1042 -3.2
## 76 1026 1033 1037 1044 -3.2
## 77 1028 1035 1037 1044 -3.2
## 78 1027 1034 1036 1043 -3.2
## 79 1030 1034 1036 1042 -3.1
## 80 1028 1032 1040 1044 -3.1
## 81 1027 1033 1036 1044 -3.1
## 82 1030 1032 1036 1043 -3.1
## 83 1026 1034 1037 1043 -3.0
## 84 1026 1034 1040 1042 -3.0
## 85 1028 1034 1037 1045 -3.0
## 86 1027 1035 1036 1043 -3.0
## 87 1026 1032 1040 1043 -2.9
## 88 1030 1032 1039 1043 -2.9
## 89 1027 1034 1040 1043 -2.8
## 90 1027 1035 1039 1043 -2.8
## 91 1026 1035 1037 1043 -2.7
## 92 1030 1033 1037 1041 -2.7
## 93 1029 1032 1040 1043 -2.6
## 94 1027 1033 1040 1041 -2.5
## 95 1030 1034 1037 1043 -2.5
## 96 1029 1035 1037 1043 -2.4
## 97 1026 1033 1037 1045 -2.3
## 98 1029 1031 1038 1042 -2.2
## 99 1030 1033 1037 1044 -2.2
## 100 1027 1033 1036 1045 -2.2
## 101 1028 1031 1039 1042 -2.1
## 102 1026 1034 1038 1042 -1.9
## 103 1030 1031 1038 1042 -1.9
## 104 1029 1033 1037 1045 -1.9
## 105 1028 1034 1036 1042 -1.8
## 106 1027 1033 1039 1045 -1.8
## 107 1027 1033 1040 1044 -1.7
## 108 1026 1035 1038 1042 -1.6
## 109 1028 1031 1040 1042 -1.5
## 110 1029 1035 1038 1042 -1.5
## 111 1030 1034 1038 1042 -1.5
## 112 1028 1035 1036 1042 -1.3
## 113 1026 1033 1039 1042 -1.2
## 114 1029 1033 1036 1042 -1.2
## 115 1028 1035 1039 1042 -1.2
## 116 1028 1034 1040 1042 -1.2
## 117 1030 1033 1036 1042 -0.6
## 118 1026 1033 1040 1042 -0.4
## 119 1030 1033 1039 1042 -0.2
## 120 1029 1033 1040 1042 0.0
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_reduced = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_fix),
p_value = median(iterated_results_table$p_fix),
R2 = NA)
model_stats_reduced %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 -3 0.025 ** moderate
# --- REDUCED VS NULL MODEL - SHOW ΔAIC & P VALUE --- #
hist(iterated_results_table$ΔAIC_fix, main = "Distribution of ΔAIC of the reduced model.")
hist(iterated_results_table$p_fix, main = "Distribution of p-values of the reduced model.")
# --- REDUCED VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_fix) %>%
arrange(ΔAIC_fix)
## system_nr_unconnected_systems ΔAIC_fix
## 1 1030 1032 1039 1041 -6.5
## 2 1026 1032 1039 1045 -6.4
## 3 1029 1032 1036 1045 -6.4
## 4 1030 1032 1036 1044 -6.4
## 5 1029 1032 1040 1041 -6.0
## 6 1026 1032 1040 1044 -5.8
## 7 1027 1031 1039 1045 -5.7
## 8 1027 1035 1039 1041 -5.6
## 9 1027 1031 1040 1044 -5.4
## 10 1027 1035 1036 1044 -5.4
## 11 1027 1034 1036 1045 -5.3
## 12 1028 1032 1036 1044 -5.2
## 13 1030 1032 1038 1044 -5.2
## 14 1027 1034 1040 1041 -5.1
## 15 1030 1031 1037 1044 -5.0
## 16 1029 1031 1037 1045 -5.0
## 17 1026 1035 1037 1044 -4.9
## 18 1028 1032 1039 1041 -4.9
## 19 1028 1032 1039 1045 -4.8
## 20 1028 1032 1036 1045 -4.8
## 21 1029 1032 1038 1045 -4.8
## 22 1026 1034 1037 1045 -4.7
## 23 1029 1035 1037 1041 -4.7
## 24 1026 1032 1038 1044 -4.6
## 25 1030 1032 1038 1041 -4.6
## 26 1029 1032 1038 1041 -4.4
## 27 1026 1032 1038 1045 -4.3
## 28 1027 1035 1038 1044 -4.3
## 29 1030 1034 1037 1041 -4.3
## 30 1028 1032 1040 1044 -4.2
## 31 1027 1034 1038 1045 -4.2
## 32 1030 1031 1039 1042 -4.1
## 33 1027 1031 1038 1044 -4.1
## 34 1028 1031 1037 1044 -4.0
## 35 1028 1035 1037 1044 -4.0
## 36 1026 1035 1039 1042 -3.9
## 37 1029 1035 1036 1042 -3.9
## 38 1027 1031 1038 1045 -3.9
## 39 1030 1034 1036 1042 -3.8
## 40 1028 1034 1037 1045 -3.8
## 41 1029 1031 1040 1042 -3.7
## 42 1028 1031 1037 1045 -3.7
## 43 1028 1032 1040 1041 -3.7
## 44 1028 1035 1036 1044 -3.6
## 45 1027 1035 1038 1041 -3.6
## 46 1027 1034 1038 1041 -3.6
## 47 1026 1034 1040 1042 -3.5
## 48 1028 1034 1036 1045 -3.5
## 49 1028 1034 1037 1041 -3.5
## 50 1026 1032 1039 1043 -3.3
## 51 1028 1031 1039 1045 -3.3
## 52 1028 1035 1039 1041 -3.3
## 53 1028 1035 1037 1041 -3.3
## 54 1029 1032 1036 1043 -3.2
## 55 1026 1035 1038 1044 -3.1
## 56 1030 1031 1038 1044 -3.1
## 57 1027 1033 1036 1044 -3.1
## 58 1027 1031 1039 1043 -3.1
## 59 1026 1033 1037 1044 -3.0
## 60 1028 1031 1040 1044 -3.0
## 61 1028 1031 1039 1042 -3.0
## 62 1027 1033 1039 1041 -3.0
## 63 1030 1032 1039 1043 -3.0
## 64 1029 1032 1040 1043 -3.0
## 65 1028 1034 1036 1042 -2.9
## 66 1029 1033 1037 1041 -2.9
## 67 1029 1031 1038 1045 -2.8
## 68 1026 1034 1038 1045 -2.8
## 69 1028 1034 1040 1041 -2.8
## 70 1029 1035 1038 1041 -2.8
## 71 1026 1032 1040 1043 -2.7
## 72 1029 1031 1037 1043 -2.7
## 73 1029 1031 1038 1042 -2.7
## 74 1030 1034 1038 1041 -2.7
## 75 1029 1035 1038 1042 -2.7
## 76 1030 1034 1038 1042 -2.7
## 77 1028 1035 1039 1042 -2.7
## 78 1027 1034 1040 1043 -2.7
## 79 1027 1031 1040 1043 -2.7
## 80 1029 1033 1037 1045 -2.6
## 81 1030 1033 1037 1044 -2.6
## 82 1027 1034 1036 1043 -2.6
## 83 1030 1032 1036 1043 -2.6
## 84 1026 1034 1038 1042 -2.5
## 85 1030 1031 1038 1042 -2.5
## 86 1030 1033 1036 1044 -2.5
## 87 1027 1033 1036 1045 -2.5
## 88 1027 1033 1039 1045 -2.5
## 89 1026 1033 1037 1045 -2.4
## 90 1028 1035 1036 1042 -2.4
## 91 1028 1034 1040 1042 -2.4
## 92 1029 1033 1036 1045 -2.3
## 93 1029 1033 1036 1042 -2.3
## 94 1027 1035 1039 1043 -2.3
## 95 1026 1034 1037 1043 -2.2
## 96 1026 1033 1039 1042 -2.2
## 97 1026 1035 1038 1042 -2.2
## 98 1030 1033 1039 1041 -2.2
## 99 1030 1033 1037 1041 -2.2
## 100 1027 1033 1040 1044 -2.2
## 101 1026 1033 1039 1045 -2.1
## 102 1028 1031 1040 1042 -2.1
## 103 1030 1031 1037 1043 -2.0
## 104 1027 1035 1036 1043 -2.0
## 105 1026 1033 1040 1044 -1.9
## 106 1029 1033 1040 1041 -1.9
## 107 1027 1033 1040 1041 -1.9
## 108 1030 1033 1036 1042 -1.8
## 109 1030 1034 1037 1043 -1.8
## 110 1029 1035 1037 1043 -1.8
## 111 1030 1033 1039 1042 -1.7
## 112 1026 1035 1037 1043 -1.6
## 113 1029 1031 1040 1043 -1.3
## 114 1029 1033 1040 1042 -1.3
## 115 1026 1033 1040 1042 -1.2
## 116 1026 1034 1040 1043 -1.1
## 117 1030 1031 1039 1043 -1.0
## 118 1026 1035 1039 1043 -0.8
## 119 1029 1035 1036 1043 -0.6
## 120 1030 1034 1036 1043 -0.6
metaecosystem_type_selected = c("Medium-Medium")
Our first step in the data analysis involves filtering the data to isolate the relevant data. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure we filtered data the right way.
# --- FILTER DATA --- #
filtered_data = ds_metaecosystems %>%
filter(time_point %in% time_points_model,
metaecosystem_type %in% metaecosystem_type_selected,
!is.na(!!sym("total_water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.metaecos.points(filtered_data,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same meta-ecosystem on multiple occasions, we can develop mixed effect models to examine how the connection influenced this meta-ecosystem variable. To study the effects of connection we compare two models to a null model using ANOVA: a full model and a reduced model. In all models, we treat system nr as having a random effect on how the slope and intercept of the relationship between response variable and time, with the slope and intercept being correlated (Bates et al. 2015). We also include the total water that was added due to evaporation in the microwave and the time point before the first disturbance (baseline). In the syntax of lmer4 the three models look this this:
Full model = response_variable ~connection * scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Reduced model = response_variable ~connection + scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Null model = response_variable ~scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Unconnected meta-ecosystems are made of paired unconnected
ecosystems, which are paired randomly. However, how to pair unconnected
ecosystems can be done in multiple ways, as unconnected ecosystems did
not interact and therefore any combination between ecosystems would be
arbitrary. To make sure that the random combination we selected did not
bias our results, we run all the possible combinations of ecosystems
constituting unconnected meta-ecosystems. The ecosystem combinations are
into the objects unconnected_combinations_sets (Data >
Meta-ecosystems). We therefore compute a p-value for each unconnected
ecosystems combination, creating a p-value distribution. We keep as
p-value of the comparison the median of such distributions.
# --- ADD BASELINES --- #
baselines = ds_metaecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(system_nr,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PREPARE TO COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
unconnected_combinations_sets_filtered = unconnected_combinations_sets %>%
filter(disturbance == disturbance_global_selected,
metaecosystem_type %in% metaecosystem_type_selected)
n_sets = unconnected_combinations_sets_filtered %>%
pull(set) %>%
max()
iterated_results_table = data.frame(Response = as.character(NA),
Levels = as.character(NA),
ΔAIC_full = NA,
p_full = NA,
ΔR2_full = NA,
ΔAIC_fix = NA,
p_fix = NA,
ΔR2_fix = NA,
combination_set = NA,
system_nr_unconnected_systems = as.character(NA)) %>%
slice(-1)
# --- COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
full_model_res_vs_fit = NULL
reduced_model_res_vs_fit = NULL
null_model_res_vs_fit = NULL
for (set_i in 1:n_sets) {
# Filter the data to contain all the connected meta-ecosystems and only a subset of unconnected meta-ecosystems
system_nr_unconnected_systems_input = unconnected_combinations_sets_filtered %>%
filter(metaecosystem_type %in% metaecosystem_type_selected,
connection == "unconnected",
set == set_i) %>%
pull(system_nr)
filtered_data_2 = filtered_data %>%
filter(connection == "connected" |
(connection == "unconnected" &
system_nr %in% system_nr_unconnected_systems_input))
# Construct models
full_model = try.different.optimizer.full.model()
reduced_model = try.different.optimizer.reduced.model()
null_model = try.different.optimizer.null.model()
# If all the optimisers fail, move on to the next iteration
if (is.null(full_model) || is.null(reduced_model) || is.null(null_model)) {
cat("This model could not be fitted with any optimiser. The unconnected meta-ecosystems in this iteration were:",
system_nr_unconnected_systems_input,
"\n")
next
}
if(plot_model_residuals_metaecos == TRUE){
# Plot residuals - full model
print(qqnorm(resid(full_model))); print(qqline(resid(full_model)))
#full_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, full_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(full_model),
residuals = resid(full_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_full_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - reduced model
print(qqnorm(resid(reduced_model))); print(qqline(resid(reduced_model)))
#reduced_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, reduced_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(reduced_model),
residuals = resid(reduced_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_reduced_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - null model
print(qqnorm(resid(null_model))); print(qqline(resid(null_model)))
#null_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, null_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(null_model),
residuals = resid(null_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_null_model.png")),
plot = plot,
width = 8,
height = 6)
}
# Give model statistics
model_stats_full = compute.model.stats(full_model,
null_model,
"mixed_model")
model_stats_reduced = compute.model.stats(reduced_model,
null_model,
"mixed_model")
# Save model statistics
iterated_results_table = fill.results.table(iterated_results_table,
response_variable_selected,
metaecosystem_type_selected,
model_stats_full,
model_stats_reduced)
iterated_results_table$set[nrow(iterated_results_table)] = set_i
iterated_results_table$system_nr_unconnected_systems[nrow(iterated_results_table)] =
paste(system_nr_unconnected_systems_input, collapse = " ")
}
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
Full vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_full = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_full),
p_value = median(iterated_results_table$p_full),
R2 = NA)
model_stats_full %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 2.7 0.511 none
# --- FULL VS NULL MODEL - SHOW ΔAIC & P VALUE DISTRIBUTIONS --- #
hist(iterated_results_table$ΔAIC_full, main = "Distribution of ΔAIC of the full model.")
hist(iterated_results_table$p_full, main = "Distribution of p-values of the full model.")
# --- FULL VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_full) %>%
arrange(ΔAIC_full)
## system_nr_unconnected_systems ΔAIC_full
## 1 1060 1065 -0.3
## 2 1065 1060 -0.3
## 3 1061 1064 -0.2
## 4 1062 1063 -0.2
## 5 1063 1062 -0.2
## 6 1064 1061 -0.2
## 7 1056 1064 0.9
## 8 1064 1056 0.9
## 9 1057 1062 1.1
## 10 1062 1057 1.1
## 11 1059 1060 1.5
## 12 1060 1059 1.5
## 13 1056 1065 2.2
## 14 1065 1056 2.2
## 15 1059 1061 2.7
## 16 1061 1059 2.7
## 17 1057 1065 3.0
## 18 1058 1062 3.0
## 19 1062 1058 3.0
## 20 1065 1057 3.0
## 21 1059 1063 3.2
## 22 1063 1059 3.2
## 23 1057 1061 3.4
## 24 1058 1064 3.4
## 25 1061 1057 3.4
## 26 1064 1058 3.4
## 27 1056 1063 3.5
## 28 1063 1056 3.5
## 29 1058 1060 3.7
## 30 1060 1058 3.7
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_reduced = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_fix),
p_value = median(iterated_results_table$p_fix),
R2 = NA)
model_stats_reduced %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 1.9 0.762 none
# --- REDUCED VS NULL MODEL - SHOW ΔAIC & P VALUE --- #
hist(iterated_results_table$ΔAIC_fix, main = "Distribution of ΔAIC of the reduced model.")
hist(iterated_results_table$p_fix, main = "Distribution of p-values of the reduced model.")
# --- REDUCED VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_fix) %>%
arrange(ΔAIC_fix)
## system_nr_unconnected_systems ΔAIC_fix
## 1 1059 1060 1.1
## 2 1060 1059 1.1
## 3 1056 1064 1.2
## 4 1057 1062 1.2
## 5 1062 1057 1.2
## 6 1064 1056 1.2
## 7 1057 1065 1.5
## 8 1065 1057 1.5
## 9 1056 1065 1.7
## 10 1065 1056 1.7
## 11 1058 1064 1.8
## 12 1059 1063 1.8
## 13 1063 1059 1.8
## 14 1064 1058 1.8
## 15 1058 1060 1.9
## 16 1059 1061 1.9
## 17 1060 1058 1.9
## 18 1061 1059 1.9
## 19 1062 1063 1.9
## 20 1063 1062 1.9
## 21 1056 1063 2.0
## 22 1057 1061 2.0
## 23 1058 1062 2.0
## 24 1060 1065 2.0
## 25 1061 1057 2.0
## 26 1061 1064 2.0
## 27 1062 1058 2.0
## 28 1063 1056 2.0
## 29 1064 1061 2.0
## 30 1065 1060 2.0
Following the initial inspection, we proceed to analyse differences among meta-ecosystems. To make it easier to interpret differences, we decided to construct a model for each comparisons we are interested in, which are: SL (connected vs unconnected) and MM (connected vs unconnected).
response_variable_selected = "bray_curtis"
metaecosystem_type_selected = c("Medium-Medium",
"Small-Large")
Here we want to look at how this meta-ecosystem variable changed across time by plotting its mean ± 95 confidence interval:
plot.metaecos.points(ds_metaecosystems,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
plot.metaecos.replicates(ds_metaecosystems,
metaecosystem_type_selected,
response_variable_selected)
metaecosystem_type_selected = c("Small-Large")
Our first step in the data analysis involves filtering the data to isolate the relevant data. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure we filtered data the right way.
# --- FILTER DATA --- #
filtered_data = ds_metaecosystems %>%
filter(time_point %in% time_points_model,
metaecosystem_type %in% metaecosystem_type_selected,
!is.na(!!sym("total_water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.metaecos.points(filtered_data,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same meta-ecosystem on multiple occasions, we can develop mixed effect models to examine how the connection influenced this meta-ecosystem variable. To study the effects of connection we compare two models to a null model using ANOVA: a full model and a reduced model. In all models, we treat system nr as having a random effect on how the slope and intercept of the relationship between response variable and time, with the slope and intercept being correlated (Bates et al. 2015). We also include the total water that was added due to evaporation in the microwave and the time point before the first disturbance (baseline). In the syntax of lmer4 the three models look this this:
Full model = response_variable ~connection * scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Reduced model = response_variable ~connection + scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Null model = response_variable ~scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Unconnected meta-ecosystems are made of paired unconnected
ecosystems, which are paired randomly. However, how to pair unconnected
ecosystems can be done in multiple ways, as unconnected ecosystems did
not interact and therefore any combination between ecosystems would be
arbitrary. To make sure that the random combination we selected did not
bias our results, we run all the possible combinations of ecosystems
constituting unconnected meta-ecosystems. The ecosystem combinations are
into the objects unconnected_combinations_sets (Data >
Meta-ecosystems). We therefore compute a p-value for each unconnected
ecosystems combination, creating a p-value distribution. We keep as
p-value of the comparison the median of such distributions.
# --- ADD BASELINES --- #
baselines = ds_metaecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(system_nr,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PREPARE TO COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
unconnected_combinations_sets_filtered = unconnected_combinations_sets %>%
filter(disturbance == disturbance_global_selected,
metaecosystem_type %in% metaecosystem_type_selected)
n_sets = unconnected_combinations_sets_filtered %>%
pull(set) %>%
max()
iterated_results_table = data.frame(Response = as.character(NA),
Levels = as.character(NA),
ΔAIC_full = NA,
p_full = NA,
ΔR2_full = NA,
ΔAIC_fix = NA,
p_fix = NA,
ΔR2_fix = NA,
combination_set = NA,
system_nr_unconnected_systems = as.character(NA)) %>%
slice(-1)
# --- COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
full_model_res_vs_fit = NULL
reduced_model_res_vs_fit = NULL
null_model_res_vs_fit = NULL
for (set_i in 1:n_sets) {
# Filter the data to contain all the connected meta-ecosystems and only a subset of unconnected meta-ecosystems
system_nr_unconnected_systems_input = unconnected_combinations_sets_filtered %>%
filter(metaecosystem_type %in% metaecosystem_type_selected,
connection == "unconnected",
set == set_i) %>%
pull(system_nr)
filtered_data_2 = filtered_data %>%
filter(connection == "connected" |
(connection == "unconnected" &
system_nr %in% system_nr_unconnected_systems_input))
# Construct models
full_model = try.different.optimizer.full.model()
reduced_model = try.different.optimizer.reduced.model()
null_model = try.different.optimizer.null.model()
# If all the optimisers fail, move on to the next iteration
if (is.null(full_model) || is.null(reduced_model) || is.null(null_model)) {
cat("This model could not be fitted with any optimiser. The unconnected meta-ecosystems in this iteration were:",
system_nr_unconnected_systems_input,
"\n")
next
}
if(plot_model_residuals_metaecos == TRUE){
# Plot residuals - full model
print(qqnorm(resid(full_model))); print(qqline(resid(full_model)))
#full_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, full_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(full_model),
residuals = resid(full_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_full_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - reduced model
print(qqnorm(resid(reduced_model))); print(qqline(resid(reduced_model)))
#reduced_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, reduced_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(reduced_model),
residuals = resid(reduced_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_reduced_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - null model
print(qqnorm(resid(null_model))); print(qqline(resid(null_model)))
#null_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, null_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(null_model),
residuals = resid(null_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_null_model.png")),
plot = plot,
width = 8,
height = 6)
}
# Give model statistics
model_stats_full = compute.model.stats(full_model,
null_model,
"mixed_model")
model_stats_reduced = compute.model.stats(reduced_model,
null_model,
"mixed_model")
# Save model statistics
iterated_results_table = fill.results.table(iterated_results_table,
response_variable_selected,
metaecosystem_type_selected,
model_stats_full,
model_stats_reduced)
iterated_results_table$set[nrow(iterated_results_table)] = set_i
iterated_results_table$system_nr_unconnected_systems[nrow(iterated_results_table)] =
paste(system_nr_unconnected_systems_input, collapse = " ")
}
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: Nelder_Mead "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: nlminbwrap "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: Nelder_Mead "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model fitting failed with all optimizers."
## This model could not be fitted with any optimiser. The unconnected meta-ecosystems in this iteration were: 1026 1034 1038 1042
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: nlminbwrap "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
Full vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_full = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_full),
p_value = median(iterated_results_table$p_full),
R2 = NA)
model_stats_full %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 -2 0.051 * weak
# --- FULL VS NULL MODEL - SHOW ΔAIC & P VALUE DISTRIBUTIONS --- #
hist(iterated_results_table$ΔAIC_full, main = "Distribution of ΔAIC of the full model.")
hist(iterated_results_table$p_full, main = "Distribution of p-values of the full model.")
# --- FULL VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_full) %>%
arrange(ΔAIC_full)
## system_nr_unconnected_systems ΔAIC_full
## 1 1028 1032 1040 1044 -5.1
## 2 1029 1032 1040 1043 -5.0
## 3 1026 1032 1040 1043 -4.9
## 4 1030 1032 1039 1043 -4.7
## 5 1028 1032 1040 1041 -4.5
## 6 1030 1032 1036 1043 -4.5
## 7 1026 1032 1039 1043 -4.3
## 8 1028 1032 1039 1045 -4.3
## 9 1029 1032 1036 1043 -4.3
## 10 1030 1033 1036 1044 -4.1
## 11 1028 1032 1036 1044 -4.1
## 12 1030 1032 1036 1044 -4.1
## 13 1030 1033 1039 1041 -4.0
## 14 1028 1032 1039 1041 -4.0
## 15 1028 1032 1036 1045 -3.9
## 16 1030 1032 1039 1041 -3.9
## 17 1029 1033 1040 1041 -3.7
## 18 1026 1032 1040 1044 -3.6
## 19 1029 1032 1040 1041 -3.6
## 20 1028 1031 1040 1044 -3.5
## 21 1030 1031 1039 1043 -3.3
## 22 1029 1031 1040 1043 -3.2
## 23 1026 1033 1040 1044 -3.2
## 24 1029 1033 1036 1045 -3.2
## 25 1027 1031 1040 1043 -3.2
## 26 1027 1034 1040 1043 -3.1
## 27 1030 1031 1037 1043 -3.0
## 28 1030 1034 1036 1043 -3.0
## 29 1027 1033 1040 1044 -3.0
## 30 1029 1032 1036 1045 -3.0
## 31 1026 1034 1040 1043 -2.9
## 32 1030 1034 1037 1043 -2.9
## 33 1028 1034 1040 1041 -2.8
## 34 1027 1033 1040 1041 -2.8
## 35 1026 1032 1039 1045 -2.7
## 36 1028 1031 1040 1042 -2.7
## 37 1027 1033 1036 1044 -2.7
## 38 1030 1032 1038 1044 -2.7
## 39 1028 1031 1039 1045 -2.6
## 40 1028 1034 1040 1042 -2.6
## 41 1026 1034 1037 1043 -2.5
## 42 1026 1033 1039 1045 -2.5
## 43 1027 1033 1039 1041 -2.5
## 44 1027 1034 1036 1043 -2.5
## 45 1027 1031 1039 1043 -2.5
## 46 1026 1035 1037 1043 -2.4
## 47 1027 1033 1039 1045 -2.4
## 48 1027 1035 1036 1043 -2.4
## 49 1030 1033 1036 1042 -2.3
## 50 1030 1033 1039 1042 -2.3
## 51 1027 1033 1036 1045 -2.3
## 52 1030 1032 1038 1041 -2.3
## 53 1029 1031 1037 1043 -2.2
## 54 1028 1034 1036 1045 -2.2
## 55 1027 1035 1039 1043 -2.2
## 56 1030 1033 1037 1044 -2.1
## 57 1026 1033 1040 1042 -2.0
## 58 1028 1035 1036 1044 -2.0
## 59 1028 1031 1039 1042 -2.0
## 60 1029 1033 1040 1042 -2.0
## 61 1029 1035 1037 1043 -2.0
## 62 1029 1035 1036 1043 -1.9
## 63 1026 1032 1038 1044 -1.8
## 64 1026 1035 1039 1043 -1.8
## 65 1028 1031 1037 1044 -1.8
## 66 1030 1033 1037 1041 -1.8
## 67 1029 1033 1036 1042 -1.7
## 68 1029 1032 1038 1045 -1.7
## 69 1028 1034 1036 1042 -1.6
## 70 1028 1035 1039 1041 -1.6
## 71 1028 1035 1039 1042 -1.6
## 72 1029 1032 1038 1041 -1.6
## 73 1026 1033 1039 1042 -1.5
## 74 1026 1032 1038 1045 -1.4
## 75 1028 1031 1037 1045 -1.4
## 76 1028 1035 1036 1042 -1.4
## 77 1028 1035 1037 1044 -1.4
## 78 1028 1034 1037 1045 -1.3
## 79 1028 1034 1037 1041 -1.2
## 80 1026 1033 1037 1044 -0.9
## 81 1029 1033 1037 1041 -0.9
## 82 1028 1035 1037 1041 -0.9
## 83 1029 1033 1037 1045 -0.8
## 84 1030 1031 1038 1042 -0.4
## 85 1026 1033 1037 1045 -0.4
## 86 1030 1034 1038 1042 -0.4
## 87 1030 1034 1036 1042 -0.2
## 88 1030 1031 1039 1042 -0.1
## 89 1026 1034 1040 1042 0.5
## 90 1026 1035 1038 1042 0.7
## 91 1029 1031 1040 1042 0.8
## 92 1029 1031 1038 1042 0.8
## 93 1030 1034 1038 1041 0.8
## 94 1029 1035 1038 1042 0.8
## 95 1030 1031 1038 1044 1.0
## 96 1026 1035 1039 1042 1.1
## 97 1029 1035 1036 1042 1.2
## 98 1030 1031 1037 1044 1.6
## 99 1030 1034 1037 1041 1.6
## 100 1027 1034 1040 1041 1.7
## 101 1027 1031 1040 1044 2.0
## 102 1027 1031 1039 1045 2.2
## 103 1029 1031 1038 1045 2.3
## 104 1027 1034 1036 1045 2.3
## 105 1027 1035 1038 1044 2.5
## 106 1027 1034 1038 1041 2.5
## 107 1027 1031 1038 1044 2.5
## 108 1027 1031 1038 1045 2.6
## 109 1029 1035 1038 1041 2.7
## 110 1027 1034 1038 1045 2.7
## 111 1026 1034 1038 1045 2.8
## 112 1026 1035 1038 1044 2.8
## 113 1027 1035 1036 1044 2.8
## 114 1027 1035 1038 1041 2.9
## 115 1029 1031 1037 1045 3.0
## 116 1027 1035 1039 1041 3.1
## 117 1026 1035 1037 1044 3.4
## 118 1029 1035 1037 1041 3.6
## 119 1026 1034 1037 1045 3.7
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_reduced = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_fix),
p_value = median(iterated_results_table$p_fix),
R2 = NA)
model_stats_reduced %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 -3.5 0.019 ** moderate
# --- REDUCED VS NULL MODEL - SHOW ΔAIC & P VALUE --- #
hist(iterated_results_table$ΔAIC_fix, main = "Distribution of ΔAIC of the reduced model.")
hist(iterated_results_table$p_fix, main = "Distribution of p-values of the reduced model.")
# --- REDUCED VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_fix) %>%
arrange(ΔAIC_fix)
## system_nr_unconnected_systems ΔAIC_fix
## 1 1028 1032 1040 1044 -7.0
## 2 1029 1032 1040 1043 -6.9
## 3 1030 1032 1039 1043 -6.7
## 4 1028 1032 1040 1041 -6.5
## 5 1026 1032 1040 1043 -6.4
## 6 1030 1032 1036 1043 -6.3
## 7 1028 1032 1039 1045 -6.1
## 8 1028 1032 1036 1044 -6.0
## 9 1029 1032 1036 1043 -6.0
## 10 1026 1032 1039 1043 -5.9
## 11 1028 1032 1039 1041 -5.9
## 12 1030 1032 1036 1044 -5.9
## 13 1028 1032 1036 1045 -5.8
## 14 1026 1032 1040 1044 -5.6
## 15 1030 1032 1039 1041 -5.5
## 16 1030 1031 1039 1043 -5.2
## 17 1029 1032 1040 1041 -5.2
## 18 1029 1031 1040 1043 -5.1
## 19 1030 1034 1036 1043 -5.0
## 20 1029 1032 1036 1045 -4.8
## 21 1028 1031 1040 1042 -4.7
## 22 1030 1033 1036 1044 -4.7
## 23 1030 1032 1038 1044 -4.7
## 24 1030 1031 1037 1043 -4.6
## 25 1026 1032 1039 1045 -4.6
## 26 1028 1031 1040 1044 -4.6
## 27 1028 1034 1040 1042 -4.6
## 28 1027 1034 1040 1043 -4.6
## 29 1030 1034 1037 1043 -4.6
## 30 1027 1031 1040 1043 -4.6
## 31 1026 1034 1040 1043 -4.5
## 32 1026 1033 1040 1044 -4.3
## 33 1030 1033 1036 1042 -4.3
## 34 1030 1033 1039 1042 -4.3
## 35 1030 1032 1038 1041 -4.3
## 36 1030 1033 1039 1041 -4.2
## 37 1027 1033 1040 1044 -4.2
## 38 1029 1033 1040 1042 -4.0
## 39 1027 1033 1036 1044 -4.0
## 40 1027 1031 1039 1043 -4.0
## 41 1026 1033 1040 1042 -3.9
## 42 1028 1031 1039 1042 -3.9
## 43 1027 1034 1036 1043 -3.8
## 44 1026 1032 1038 1044 -3.7
## 45 1029 1035 1036 1043 -3.7
## 46 1028 1031 1037 1044 -3.7
## 47 1028 1034 1040 1041 -3.7
## 48 1029 1033 1036 1042 -3.7
## 49 1027 1033 1040 1041 -3.7
## 50 1029 1032 1038 1045 -3.7
## 51 1029 1031 1037 1043 -3.6
## 52 1028 1031 1039 1045 -3.6
## 53 1028 1034 1036 1042 -3.6
## 54 1029 1033 1040 1041 -3.6
## 55 1028 1035 1039 1042 -3.6
## 56 1029 1032 1038 1041 -3.6
## 57 1026 1033 1039 1042 -3.5
## 58 1030 1033 1037 1044 -3.5
## 59 1027 1033 1036 1045 -3.5
## 60 1027 1033 1039 1045 -3.5
## 61 1026 1032 1038 1045 -3.4
## 62 1028 1035 1037 1044 -3.4
## 63 1027 1033 1039 1041 -3.4
## 64 1026 1034 1037 1043 -3.3
## 65 1026 1035 1039 1043 -3.3
## 66 1026 1033 1039 1045 -3.3
## 67 1028 1031 1037 1045 -3.3
## 68 1028 1035 1036 1042 -3.3
## 69 1028 1035 1036 1044 -3.3
## 70 1029 1033 1036 1045 -3.3
## 71 1027 1035 1039 1043 -3.3
## 72 1028 1034 1037 1045 -3.2
## 73 1028 1034 1037 1041 -3.2
## 74 1030 1033 1037 1041 -3.2
## 75 1028 1034 1036 1045 -3.1
## 76 1029 1035 1037 1043 -3.1
## 77 1027 1035 1036 1043 -3.0
## 78 1028 1035 1037 1041 -2.9
## 79 1026 1033 1037 1044 -2.8
## 80 1028 1035 1039 1041 -2.8
## 81 1026 1035 1037 1043 -2.5
## 82 1026 1033 1037 1045 -2.3
## 83 1029 1033 1037 1041 -2.2
## 84 1029 1033 1037 1045 -2.2
## 85 1030 1031 1038 1042 -2.1
## 86 1030 1034 1038 1042 -2.1
## 87 1030 1034 1036 1042 -2.0
## 88 1030 1031 1039 1042 -1.9
## 89 1029 1031 1040 1042 -1.0
## 90 1029 1031 1038 1042 -0.8
## 91 1026 1034 1040 1042 -0.6
## 92 1030 1031 1038 1044 -0.6
## 93 1029 1035 1038 1042 -0.5
## 94 1030 1034 1038 1041 -0.3
## 95 1029 1035 1036 1042 -0.2
## 96 1030 1031 1037 1044 0.0
## 97 1026 1035 1038 1042 0.2
## 98 1030 1034 1037 1041 0.2
## 99 1026 1035 1039 1042 0.4
## 100 1027 1035 1038 1044 0.6
## 101 1027 1031 1038 1044 0.6
## 102 1027 1034 1038 1041 0.7
## 103 1027 1031 1040 1044 0.7
## 104 1027 1031 1038 1045 0.7
## 105 1029 1031 1038 1045 0.8
## 106 1026 1035 1038 1044 0.8
## 107 1027 1034 1038 1045 0.8
## 108 1026 1034 1038 1045 0.9
## 109 1027 1035 1038 1041 0.9
## 110 1027 1035 1036 1044 0.9
## 111 1029 1035 1038 1041 1.1
## 112 1027 1034 1040 1041 1.1
## 113 1027 1034 1036 1045 1.1
## 114 1027 1031 1039 1045 1.1
## 115 1026 1035 1037 1044 1.5
## 116 1027 1035 1039 1041 1.6
## 117 1026 1034 1037 1045 1.7
## 118 1029 1031 1037 1045 1.7
## 119 1029 1035 1037 1041 1.8
metaecosystem_type_selected = c("Medium-Medium")
Our first step in the data analysis involves filtering the data to isolate the relevant data. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure we filtered data the right way.
# --- FILTER DATA --- #
filtered_data = ds_metaecosystems %>%
filter(time_point %in% time_points_model,
metaecosystem_type %in% metaecosystem_type_selected,
!is.na(!!sym("total_water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.metaecos.points(filtered_data,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same meta-ecosystem on multiple occasions, we can develop mixed effect models to examine how the connection influenced this meta-ecosystem variable. To study the effects of connection we compare two models to a null model using ANOVA: a full model and a reduced model. In all models, we treat system nr as having a random effect on how the slope and intercept of the relationship between response variable and time, with the slope and intercept being correlated (Bates et al. 2015). We also include the total water that was added due to evaporation in the microwave and the time point before the first disturbance (baseline). In the syntax of lmer4 the three models look this this:
Full model = response_variable ~connection * scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Reduced model = response_variable ~connection + scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Null model = response_variable ~scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Unconnected meta-ecosystems are made of paired unconnected
ecosystems, which are paired randomly. However, how to pair unconnected
ecosystems can be done in multiple ways, as unconnected ecosystems did
not interact and therefore any combination between ecosystems would be
arbitrary. To make sure that the random combination we selected did not
bias our results, we run all the possible combinations of ecosystems
constituting unconnected meta-ecosystems. The ecosystem combinations are
into the objects unconnected_combinations_sets (Data >
Meta-ecosystems). We therefore compute a p-value for each unconnected
ecosystems combination, creating a p-value distribution. We keep as
p-value of the comparison the median of such distributions.
# --- ADD BASELINES --- #
baselines = ds_metaecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(system_nr,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PREPARE TO COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
unconnected_combinations_sets_filtered = unconnected_combinations_sets %>%
filter(disturbance == disturbance_global_selected,
metaecosystem_type %in% metaecosystem_type_selected)
n_sets = unconnected_combinations_sets_filtered %>%
pull(set) %>%
max()
iterated_results_table = data.frame(Response = as.character(NA),
Levels = as.character(NA),
ΔAIC_full = NA,
p_full = NA,
ΔR2_full = NA,
ΔAIC_fix = NA,
p_fix = NA,
ΔR2_fix = NA,
combination_set = NA,
system_nr_unconnected_systems = as.character(NA)) %>%
slice(-1)
# --- COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
full_model_res_vs_fit = NULL
reduced_model_res_vs_fit = NULL
null_model_res_vs_fit = NULL
for (set_i in 1:n_sets) {
# Filter the data to contain all the connected meta-ecosystems and only a subset of unconnected meta-ecosystems
system_nr_unconnected_systems_input = unconnected_combinations_sets_filtered %>%
filter(metaecosystem_type %in% metaecosystem_type_selected,
connection == "unconnected",
set == set_i) %>%
pull(system_nr)
filtered_data_2 = filtered_data %>%
filter(connection == "connected" |
(connection == "unconnected" &
system_nr %in% system_nr_unconnected_systems_input))
# Construct models
full_model = try.different.optimizer.full.model()
reduced_model = try.different.optimizer.reduced.model()
null_model = try.different.optimizer.null.model()
# If all the optimisers fail, move on to the next iteration
if (is.null(full_model) || is.null(reduced_model) || is.null(null_model)) {
cat("This model could not be fitted with any optimiser. The unconnected meta-ecosystems in this iteration were:",
system_nr_unconnected_systems_input,
"\n")
next
}
if(plot_model_residuals_metaecos == TRUE){
# Plot residuals - full model
print(qqnorm(resid(full_model))); print(qqline(resid(full_model)))
#full_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, full_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(full_model),
residuals = resid(full_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_full_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - reduced model
print(qqnorm(resid(reduced_model))); print(qqline(resid(reduced_model)))
#reduced_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, reduced_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(reduced_model),
residuals = resid(reduced_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_reduced_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - null model
print(qqnorm(resid(null_model))); print(qqline(resid(null_model)))
#null_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, null_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(null_model),
residuals = resid(null_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_null_model.png")),
plot = plot,
width = 8,
height = 6)
}
# Give model statistics
model_stats_full = compute.model.stats(full_model,
null_model,
"mixed_model")
model_stats_reduced = compute.model.stats(reduced_model,
null_model,
"mixed_model")
# Save model statistics
iterated_results_table = fill.results.table(iterated_results_table,
response_variable_selected,
metaecosystem_type_selected,
model_stats_full,
model_stats_reduced)
iterated_results_table$set[nrow(iterated_results_table)] = set_i
iterated_results_table$system_nr_unconnected_systems[nrow(iterated_results_table)] =
paste(system_nr_unconnected_systems_input, collapse = " ")
}
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
Full vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_full = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_full),
p_value = median(iterated_results_table$p_full),
R2 = NA)
model_stats_full %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 3 0.617 none
# --- FULL VS NULL MODEL - SHOW ΔAIC & P VALUE DISTRIBUTIONS --- #
hist(iterated_results_table$ΔAIC_full, main = "Distribution of ΔAIC of the full model.")
hist(iterated_results_table$p_full, main = "Distribution of p-values of the full model.")
# --- FULL VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_full) %>%
arrange(ΔAIC_full)
## system_nr_unconnected_systems ΔAIC_full
## 1 1059 1060 -0.8
## 2 1060 1059 -0.8
## 3 1058 1062 0.8
## 4 1062 1058 0.8
## 5 1059 1061 1.0
## 6 1061 1059 1.0
## 7 1061 1064 1.5
## 8 1064 1061 1.5
## 9 1060 1065 1.6
## 10 1065 1060 1.6
## 11 1056 1063 2.6
## 12 1063 1056 2.6
## 13 1057 1062 2.7
## 14 1062 1057 2.7
## 15 1062 1063 3.0
## 16 1063 1062 3.0
## 17 1059 1063 3.2
## 18 1063 1059 3.2
## 19 1056 1064 3.6
## 20 1057 1061 3.6
## 21 1058 1060 3.6
## 22 1060 1058 3.6
## 23 1061 1057 3.6
## 24 1064 1056 3.6
## 25 1058 1064 3.7
## 26 1064 1058 3.7
## 27 1057 1065 3.8
## 28 1065 1057 3.8
## 29 1056 1065 3.9
## 30 1065 1056 3.9
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_reduced = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_fix),
p_value = median(iterated_results_table$p_fix),
R2 = NA)
model_stats_reduced %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 1.6 0.53 none
# --- REDUCED VS NULL MODEL - SHOW ΔAIC & P VALUE --- #
hist(iterated_results_table$ΔAIC_fix, main = "Distribution of ΔAIC of the reduced model.")
hist(iterated_results_table$p_fix, main = "Distribution of p-values of the reduced model.")
# --- REDUCED VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_fix) %>%
arrange(ΔAIC_fix)
## system_nr_unconnected_systems ΔAIC_fix
## 1 1059 1061 -0.3
## 2 1061 1059 -0.3
## 3 1058 1062 0.1
## 4 1062 1058 0.1
## 5 1057 1062 0.9
## 6 1059 1060 0.9
## 7 1060 1059 0.9
## 8 1062 1057 0.9
## 9 1061 1064 1.1
## 10 1062 1063 1.1
## 11 1063 1062 1.1
## 12 1064 1061 1.1
## 13 1059 1063 1.5
## 14 1063 1059 1.5
## 15 1056 1064 1.6
## 16 1058 1060 1.6
## 17 1060 1058 1.6
## 18 1064 1056 1.6
## 19 1057 1061 1.7
## 20 1058 1064 1.7
## 21 1061 1057 1.7
## 22 1064 1058 1.7
## 23 1056 1063 1.9
## 24 1056 1065 1.9
## 25 1057 1065 1.9
## 26 1063 1056 1.9
## 27 1065 1056 1.9
## 28 1065 1057 1.9
## 29 1060 1065 2.0
## 30 1065 1060 2.0
Following the initial inspection, we proceed to analyse differences among meta-ecosystems. To make it easier to interpret differences, we decided to construct a model for each comparisons we are interested in, which are: SL (connected vs unconnected) and MM (connected vs unconnected).
response_variable_selected = "metaecosystem_richness"
metaecosystem_type_selected = c("Medium-Medium",
"Small-Large")
Here we want to look at how this meta-ecosystem variable changed across time by plotting its mean ± 95 confidence interval:
plot.metaecos.points(ds_metaecosystems,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
plot.metaecos.replicates(ds_metaecosystems,
metaecosystem_type_selected,
response_variable_selected)
metaecosystem_type_selected = c("Small-Large")
Our first step in the data analysis involves filtering the data to isolate the relevant data. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure we filtered data the right way.
# --- FILTER DATA --- #
filtered_data = ds_metaecosystems %>%
filter(time_point %in% time_points_model,
metaecosystem_type %in% metaecosystem_type_selected,
!is.na(!!sym("total_water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.metaecos.points(filtered_data,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same meta-ecosystem on multiple occasions, we can develop mixed effect models to examine how the connection influenced this meta-ecosystem variable. To study the effects of connection we compare two models to a null model using ANOVA: a full model and a reduced model. In all models, we treat system nr as having a random effect on how the slope and intercept of the relationship between response variable and time, with the slope and intercept being correlated (Bates et al. 2015). We also include the total water that was added due to evaporation in the microwave and the time point before the first disturbance (baseline). In the syntax of lmer4 the three models look this this:
Full model = response_variable ~connection * scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Reduced model = response_variable ~connection + scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Null model = response_variable ~scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Unconnected meta-ecosystems are made of paired unconnected
ecosystems, which are paired randomly. However, how to pair unconnected
ecosystems can be done in multiple ways, as unconnected ecosystems did
not interact and therefore any combination between ecosystems would be
arbitrary. To make sure that the random combination we selected did not
bias our results, we run all the possible combinations of ecosystems
constituting unconnected meta-ecosystems. The ecosystem combinations are
into the objects unconnected_combinations_sets (Data >
Meta-ecosystems). We therefore compute a p-value for each unconnected
ecosystems combination, creating a p-value distribution. We keep as
p-value of the comparison the median of such distributions.
# --- ADD BASELINES --- #
baselines = ds_metaecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(system_nr,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PREPARE TO COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
unconnected_combinations_sets_filtered = unconnected_combinations_sets %>%
filter(disturbance == disturbance_global_selected,
metaecosystem_type %in% metaecosystem_type_selected)
n_sets = unconnected_combinations_sets_filtered %>%
pull(set) %>%
max()
iterated_results_table = data.frame(Response = as.character(NA),
Levels = as.character(NA),
ΔAIC_full = NA,
p_full = NA,
ΔR2_full = NA,
ΔAIC_fix = NA,
p_fix = NA,
ΔR2_fix = NA,
combination_set = NA,
system_nr_unconnected_systems = as.character(NA)) %>%
slice(-1)
# --- COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
full_model_res_vs_fit = NULL
reduced_model_res_vs_fit = NULL
null_model_res_vs_fit = NULL
for (set_i in 1:n_sets) {
# Filter the data to contain all the connected meta-ecosystems and only a subset of unconnected meta-ecosystems
system_nr_unconnected_systems_input = unconnected_combinations_sets_filtered %>%
filter(metaecosystem_type %in% metaecosystem_type_selected,
connection == "unconnected",
set == set_i) %>%
pull(system_nr)
filtered_data_2 = filtered_data %>%
filter(connection == "connected" |
(connection == "unconnected" &
system_nr %in% system_nr_unconnected_systems_input))
# Construct models
full_model = try.different.optimizer.full.model()
reduced_model = try.different.optimizer.reduced.model()
null_model = try.different.optimizer.null.model()
# If all the optimisers fail, move on to the next iteration
if (is.null(full_model) || is.null(reduced_model) || is.null(null_model)) {
cat("This model could not be fitted with any optimiser. The unconnected meta-ecosystems in this iteration were:",
system_nr_unconnected_systems_input,
"\n")
next
}
if(plot_model_residuals_metaecos == TRUE){
# Plot residuals - full model
print(qqnorm(resid(full_model))); print(qqline(resid(full_model)))
#full_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, full_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(full_model),
residuals = resid(full_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_full_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - reduced model
print(qqnorm(resid(reduced_model))); print(qqline(resid(reduced_model)))
#reduced_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, reduced_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(reduced_model),
residuals = resid(reduced_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_reduced_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - null model
print(qqnorm(resid(null_model))); print(qqline(resid(null_model)))
#null_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, null_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(null_model),
residuals = resid(null_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_null_model.png")),
plot = plot,
width = 8,
height = 6)
}
# Give model statistics
model_stats_full = compute.model.stats(full_model,
null_model,
"mixed_model")
model_stats_reduced = compute.model.stats(reduced_model,
null_model,
"mixed_model")
# Save model statistics
iterated_results_table = fill.results.table(iterated_results_table,
response_variable_selected,
metaecosystem_type_selected,
model_stats_full,
model_stats_reduced)
iterated_results_table$set[nrow(iterated_results_table)] = set_i
iterated_results_table$system_nr_unconnected_systems[nrow(iterated_results_table)] =
paste(system_nr_unconnected_systems_input, collapse = " ")
}
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
Full vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_full = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_full),
p_value = median(iterated_results_table$p_full),
R2 = NA)
model_stats_full %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 1.7 0.318 none
# --- FULL VS NULL MODEL - SHOW ΔAIC & P VALUE DISTRIBUTIONS --- #
hist(iterated_results_table$ΔAIC_full, main = "Distribution of ΔAIC of the full model.")
hist(iterated_results_table$p_full, main = "Distribution of p-values of the full model.")
# --- FULL VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_full) %>%
arrange(ΔAIC_full)
## system_nr_unconnected_systems ΔAIC_full
## 1 1030 1033 1036 1044 -2.0
## 2 1026 1033 1040 1044 -1.5
## 3 1030 1033 1039 1041 -1.2
## 4 1028 1031 1040 1044 -0.9
## 5 1026 1033 1039 1045 -0.8
## 6 1026 1035 1038 1044 -0.8
## 7 1030 1031 1038 1044 -0.8
## 8 1030 1033 1036 1042 -0.7
## 9 1029 1033 1036 1045 -0.6
## 10 1028 1035 1037 1041 -0.5
## 11 1026 1033 1040 1042 -0.3
## 12 1028 1035 1039 1041 -0.3
## 13 1028 1031 1040 1042 -0.1
## 14 1030 1033 1037 1041 -0.1
## 15 1029 1033 1040 1041 0.0
## 16 1029 1031 1038 1045 0.1
## 17 1026 1035 1038 1042 0.1
## 18 1028 1035 1036 1044 0.1
## 19 1026 1032 1038 1045 0.2
## 20 1030 1031 1038 1042 0.2
## 21 1029 1035 1038 1041 0.2
## 22 1027 1031 1038 1045 0.2
## 23 1026 1032 1038 1044 0.3
## 24 1026 1033 1037 1045 0.3
## 25 1028 1032 1040 1041 0.3
## 26 1027 1031 1038 1044 0.3
## 27 1028 1031 1037 1045 0.4
## 28 1027 1033 1036 1045 0.4
## 29 1028 1031 1037 1044 0.5
## 30 1030 1034 1038 1041 0.7
## 31 1027 1035 1038 1041 0.7
## 32 1030 1032 1038 1041 0.7
## 33 1028 1031 1039 1045 0.8
## 34 1027 1033 1036 1044 0.8
## 35 1026 1033 1037 1044 0.9
## 36 1028 1035 1036 1042 0.9
## 37 1028 1032 1036 1044 0.9
## 38 1027 1033 1040 1041 0.9
## 39 1026 1034 1038 1045 1.0
## 40 1028 1034 1040 1041 1.0
## 41 1030 1033 1037 1044 1.0
## 42 1026 1035 1037 1043 1.1
## 43 1029 1031 1038 1042 1.1
## 44 1028 1032 1036 1045 1.1
## 45 1026 1032 1040 1043 1.2
## 46 1030 1031 1037 1043 1.2
## 47 1026 1035 1039 1043 1.2
## 48 1029 1033 1036 1042 1.3
## 49 1027 1033 1040 1044 1.3
## 50 1027 1031 1040 1043 1.3
## 51 1030 1033 1039 1042 1.4
## 52 1028 1032 1040 1044 1.4
## 53 1030 1031 1039 1043 1.5
## 54 1029 1031 1040 1043 1.6
## 55 1028 1031 1039 1042 1.6
## 56 1029 1033 1040 1042 1.6
## 57 1030 1032 1036 1043 1.6
## 58 1027 1035 1036 1043 1.6
## 59 1026 1034 1038 1042 1.7
## 60 1026 1033 1039 1042 1.7
## 61 1028 1035 1037 1044 1.7
## 62 1029 1035 1036 1043 1.8
## 63 1028 1032 1039 1041 1.8
## 64 1027 1035 1038 1044 1.8
## 65 1026 1032 1040 1044 1.9
## 66 1030 1032 1038 1044 1.9
## 67 1029 1032 1038 1041 1.9
## 68 1029 1031 1037 1043 2.0
## 69 1028 1034 1036 1045 2.0
## 70 1027 1031 1040 1044 2.0
## 71 1026 1032 1039 1043 2.1
## 72 1026 1034 1040 1043 2.1
## 73 1029 1032 1036 1043 2.1
## 74 1026 1035 1037 1044 2.2
## 75 1029 1033 1037 1041 2.2
## 76 1027 1031 1039 1043 2.2
## 77 1030 1031 1037 1044 2.3
## 78 1030 1034 1036 1043 2.3
## 79 1028 1034 1037 1041 2.3
## 80 1029 1032 1038 1045 2.3
## 81 1028 1034 1036 1042 2.4
## 82 1029 1033 1037 1045 2.4
## 83 1029 1035 1038 1042 2.4
## 84 1027 1033 1039 1045 2.4
## 85 1027 1034 1038 1041 2.4
## 86 1029 1032 1040 1043 2.4
## 87 1028 1035 1039 1042 2.5
## 88 1027 1033 1039 1041 2.5
## 89 1027 1035 1036 1044 2.5
## 90 1030 1032 1036 1044 2.5
## 91 1026 1034 1037 1043 2.6
## 92 1028 1032 1039 1045 2.6
## 93 1029 1031 1040 1042 2.7
## 94 1028 1034 1040 1042 2.7
## 95 1030 1032 1039 1043 2.7
## 96 1027 1034 1036 1043 2.7
## 97 1026 1032 1039 1045 2.8
## 98 1030 1034 1038 1042 2.8
## 99 1027 1034 1038 1045 2.8
## 100 1027 1035 1039 1043 2.8
## 101 1029 1035 1037 1043 2.8
## 102 1026 1035 1039 1042 2.9
## 103 1030 1031 1039 1042 2.9
## 104 1027 1034 1040 1043 2.9
## 105 1029 1032 1036 1045 2.9
## 106 1027 1031 1039 1045 2.9
## 107 1029 1031 1037 1045 3.0
## 108 1029 1032 1040 1041 3.0
## 109 1026 1034 1040 1042 3.1
## 110 1029 1035 1036 1042 3.2
## 111 1030 1034 1037 1043 3.3
## 112 1029 1035 1037 1041 3.3
## 113 1030 1032 1039 1041 3.3
## 114 1027 1035 1039 1041 3.3
## 115 1026 1034 1037 1045 3.4
## 116 1028 1034 1037 1045 3.4
## 117 1027 1034 1040 1041 3.4
## 118 1027 1034 1036 1045 3.4
## 119 1030 1034 1036 1042 3.5
## 120 1030 1034 1037 1041 3.5
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_reduced = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_fix),
p_value = median(iterated_results_table$p_fix),
R2 = NA)
model_stats_reduced %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 0 0.162 none
# --- REDUCED VS NULL MODEL - SHOW ΔAIC & P VALUE --- #
hist(iterated_results_table$ΔAIC_fix, main = "Distribution of ΔAIC of the reduced model.")
hist(iterated_results_table$p_fix, main = "Distribution of p-values of the reduced model.")
# --- REDUCED VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_fix) %>%
arrange(ΔAIC_fix)
## system_nr_unconnected_systems ΔAIC_fix
## 1 1026 1033 1040 1044 -2.0
## 2 1028 1031 1040 1044 -1.7
## 3 1026 1032 1038 1044 -1.6
## 4 1026 1033 1040 1042 -1.6
## 5 1030 1033 1036 1044 -1.6
## 6 1027 1031 1038 1044 -1.6
## 7 1028 1031 1040 1042 -1.5
## 8 1028 1031 1037 1044 -1.4
## 9 1026 1032 1038 1045 -1.3
## 10 1030 1033 1036 1042 -1.3
## 11 1027 1031 1038 1045 -1.3
## 12 1026 1033 1037 1045 -1.2
## 13 1027 1033 1036 1045 -1.2
## 14 1026 1033 1037 1044 -1.1
## 15 1028 1035 1037 1041 -1.1
## 16 1028 1032 1040 1041 -1.1
## 17 1028 1032 1036 1044 -1.1
## 18 1027 1033 1036 1044 -1.1
## 19 1026 1035 1038 1044 -1.0
## 20 1030 1031 1038 1044 -1.0
## 21 1026 1035 1038 1042 -1.0
## 22 1028 1031 1037 1045 -1.0
## 23 1030 1033 1037 1041 -1.0
## 24 1030 1031 1038 1042 -0.9
## 25 1026 1032 1040 1043 -0.8
## 26 1026 1035 1037 1043 -0.8
## 27 1026 1033 1039 1045 -0.8
## 28 1027 1033 1040 1041 -0.8
## 29 1030 1031 1037 1043 -0.7
## 30 1029 1031 1038 1042 -0.7
## 31 1028 1035 1036 1044 -0.7
## 32 1029 1033 1036 1045 -0.7
## 33 1030 1033 1037 1044 -0.7
## 34 1028 1032 1036 1045 -0.7
## 35 1027 1033 1040 1044 -0.7
## 36 1027 1031 1040 1043 -0.7
## 37 1028 1035 1036 1042 -0.6
## 38 1028 1032 1040 1044 -0.6
## 39 1029 1033 1040 1041 -0.5
## 40 1029 1033 1036 1042 -0.5
## 41 1027 1035 1038 1041 -0.4
## 42 1030 1032 1038 1041 -0.4
## 43 1030 1032 1036 1043 -0.4
## 44 1029 1031 1038 1045 -0.3
## 45 1026 1033 1039 1042 -0.3
## 46 1028 1031 1039 1042 -0.3
## 47 1030 1033 1039 1041 -0.3
## 48 1027 1035 1036 1043 -0.3
## 49 1029 1031 1040 1043 -0.2
## 50 1029 1033 1040 1042 -0.2
## 51 1026 1035 1039 1043 -0.1
## 52 1028 1032 1039 1041 -0.1
## 53 1028 1035 1037 1044 -0.1
## 54 1027 1035 1038 1044 -0.1
## 55 1026 1032 1040 1044 0.0
## 56 1030 1031 1039 1043 0.0
## 57 1026 1034 1038 1042 0.0
## 58 1030 1033 1039 1042 0.0
## 59 1030 1032 1038 1044 0.0
## 60 1029 1032 1038 1041 0.0
## 61 1027 1031 1040 1044 0.1
## 62 1026 1035 1037 1044 0.2
## 63 1029 1035 1036 1043 0.2
## 64 1028 1031 1039 1045 0.2
## 65 1030 1031 1037 1044 0.3
## 66 1028 1035 1039 1041 0.3
## 67 1029 1033 1037 1041 0.3
## 68 1029 1032 1036 1043 0.3
## 69 1026 1034 1040 1043 0.4
## 70 1027 1033 1039 1045 0.4
## 71 1029 1032 1038 1045 0.4
## 72 1026 1032 1039 1043 0.5
## 73 1029 1031 1037 1043 0.5
## 74 1028 1034 1036 1042 0.5
## 75 1029 1035 1038 1041 0.5
## 76 1029 1033 1037 1045 0.5
## 77 1028 1034 1037 1041 0.5
## 78 1027 1033 1039 1041 0.5
## 79 1027 1035 1036 1044 0.5
## 80 1030 1032 1036 1044 0.5
## 81 1029 1035 1038 1042 0.6
## 82 1028 1035 1039 1042 0.6
## 83 1028 1032 1039 1045 0.6
## 84 1027 1034 1038 1041 0.6
## 85 1027 1031 1039 1043 0.6
## 86 1029 1031 1040 1042 0.7
## 87 1029 1032 1040 1043 0.7
## 88 1030 1034 1036 1043 0.8
## 89 1026 1034 1038 1045 0.8
## 90 1028 1034 1040 1041 0.8
## 91 1028 1034 1040 1042 0.8
## 92 1027 1034 1036 1043 0.8
## 93 1026 1034 1037 1043 0.9
## 94 1026 1035 1039 1042 0.9
## 95 1027 1034 1038 1045 0.9
## 96 1027 1035 1039 1043 0.9
## 97 1030 1032 1039 1043 0.9
## 98 1029 1035 1037 1043 0.9
## 99 1026 1032 1039 1045 1.0
## 100 1030 1031 1039 1042 1.0
## 101 1029 1032 1036 1045 1.0
## 102 1026 1034 1040 1042 1.1
## 103 1029 1031 1037 1045 1.1
## 104 1030 1034 1038 1042 1.1
## 105 1027 1034 1040 1043 1.1
## 106 1027 1031 1039 1045 1.1
## 107 1029 1035 1036 1042 1.2
## 108 1030 1034 1038 1041 1.2
## 109 1029 1032 1040 1041 1.2
## 110 1028 1034 1036 1045 1.3
## 111 1030 1034 1037 1043 1.3
## 112 1029 1035 1037 1041 1.3
## 113 1030 1032 1039 1041 1.3
## 114 1027 1035 1039 1041 1.3
## 115 1027 1034 1036 1045 1.4
## 116 1026 1034 1037 1045 1.5
## 117 1030 1034 1036 1042 1.5
## 118 1028 1034 1037 1045 1.5
## 119 1030 1034 1037 1041 1.5
## 120 1027 1034 1040 1041 1.5
metaecosystem_type_selected = c("Medium-Medium")
Our first step in the data analysis involves filtering the data to isolate the relevant data. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure we filtered data the right way.
# --- FILTER DATA --- #
filtered_data = ds_metaecosystems %>%
filter(time_point %in% time_points_model,
metaecosystem_type %in% metaecosystem_type_selected,
!is.na(!!sym("total_water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.metaecos.points(filtered_data,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same meta-ecosystem on multiple occasions, we can develop mixed effect models to examine how the connection influenced this meta-ecosystem variable. To study the effects of connection we compare two models to a null model using ANOVA: a full model and a reduced model. In all models, we treat system nr as having a random effect on how the slope and intercept of the relationship between response variable and time, with the slope and intercept being correlated (Bates et al. 2015). We also include the total water that was added due to evaporation in the microwave and the time point before the first disturbance (baseline). In the syntax of lmer4 the three models look this this:
Full model = response_variable ~connection * scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Reduced model = response_variable ~connection + scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Null model = response_variable ~scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Unconnected meta-ecosystems are made of paired unconnected
ecosystems, which are paired randomly. However, how to pair unconnected
ecosystems can be done in multiple ways, as unconnected ecosystems did
not interact and therefore any combination between ecosystems would be
arbitrary. To make sure that the random combination we selected did not
bias our results, we run all the possible combinations of ecosystems
constituting unconnected meta-ecosystems. The ecosystem combinations are
into the objects unconnected_combinations_sets (Data >
Meta-ecosystems). We therefore compute a p-value for each unconnected
ecosystems combination, creating a p-value distribution. We keep as
p-value of the comparison the median of such distributions.
# --- ADD BASELINES --- #
baselines = ds_metaecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(system_nr,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PREPARE TO COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
unconnected_combinations_sets_filtered = unconnected_combinations_sets %>%
filter(disturbance == disturbance_global_selected,
metaecosystem_type %in% metaecosystem_type_selected)
n_sets = unconnected_combinations_sets_filtered %>%
pull(set) %>%
max()
iterated_results_table = data.frame(Response = as.character(NA),
Levels = as.character(NA),
ΔAIC_full = NA,
p_full = NA,
ΔR2_full = NA,
ΔAIC_fix = NA,
p_fix = NA,
ΔR2_fix = NA,
combination_set = NA,
system_nr_unconnected_systems = as.character(NA)) %>%
slice(-1)
# --- COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
full_model_res_vs_fit = NULL
reduced_model_res_vs_fit = NULL
null_model_res_vs_fit = NULL
for (set_i in 1:n_sets) {
# Filter the data to contain all the connected meta-ecosystems and only a subset of unconnected meta-ecosystems
system_nr_unconnected_systems_input = unconnected_combinations_sets_filtered %>%
filter(metaecosystem_type %in% metaecosystem_type_selected,
connection == "unconnected",
set == set_i) %>%
pull(system_nr)
filtered_data_2 = filtered_data %>%
filter(connection == "connected" |
(connection == "unconnected" &
system_nr %in% system_nr_unconnected_systems_input))
# Construct models
full_model = try.different.optimizer.full.model()
reduced_model = try.different.optimizer.reduced.model()
null_model = try.different.optimizer.null.model()
# If all the optimisers fail, move on to the next iteration
if (is.null(full_model) || is.null(reduced_model) || is.null(null_model)) {
cat("This model could not be fitted with any optimiser. The unconnected meta-ecosystems in this iteration were:",
system_nr_unconnected_systems_input,
"\n")
next
}
if(plot_model_residuals_metaecos == TRUE){
# Plot residuals - full model
print(qqnorm(resid(full_model))); print(qqline(resid(full_model)))
#full_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, full_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(full_model),
residuals = resid(full_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_full_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - reduced model
print(qqnorm(resid(reduced_model))); print(qqline(resid(reduced_model)))
#reduced_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, reduced_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(reduced_model),
residuals = resid(reduced_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_reduced_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - null model
print(qqnorm(resid(null_model))); print(qqline(resid(null_model)))
#null_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, null_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(null_model),
residuals = resid(null_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_null_model.png")),
plot = plot,
width = 8,
height = 6)
}
# Give model statistics
model_stats_full = compute.model.stats(full_model,
null_model,
"mixed_model")
model_stats_reduced = compute.model.stats(reduced_model,
null_model,
"mixed_model")
# Save model statistics
iterated_results_table = fill.results.table(iterated_results_table,
response_variable_selected,
metaecosystem_type_selected,
model_stats_full,
model_stats_reduced)
iterated_results_table$set[nrow(iterated_results_table)] = set_i
iterated_results_table$system_nr_unconnected_systems[nrow(iterated_results_table)] =
paste(system_nr_unconnected_systems_input, collapse = " ")
}
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
Full vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_full = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_full),
p_value = median(iterated_results_table$p_full),
R2 = NA)
model_stats_full %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 2.7 0.522 none
# --- FULL VS NULL MODEL - SHOW ΔAIC & P VALUE DISTRIBUTIONS --- #
hist(iterated_results_table$ΔAIC_full, main = "Distribution of ΔAIC of the full model.")
hist(iterated_results_table$p_full, main = "Distribution of p-values of the full model.")
# --- FULL VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_full) %>%
arrange(ΔAIC_full)
## system_nr_unconnected_systems ΔAIC_full
## 1 1057 1062 -0.5
## 2 1062 1057 -0.5
## 3 1056 1064 0.4
## 4 1064 1056 0.4
## 5 1062 1063 0.6
## 6 1063 1062 0.6
## 7 1056 1065 0.8
## 8 1059 1060 0.8
## 9 1060 1059 0.8
## 10 1065 1056 0.8
## 11 1056 1063 2.1
## 12 1063 1056 2.1
## 13 1058 1064 2.4
## 14 1064 1058 2.4
## 15 1058 1060 2.7
## 16 1060 1058 2.7
## 17 1061 1064 2.8
## 18 1064 1061 2.8
## 19 1059 1063 2.9
## 20 1063 1059 2.9
## 21 1060 1065 3.2
## 22 1065 1060 3.2
## 23 1059 1061 3.3
## 24 1061 1059 3.3
## 25 1057 1061 3.4
## 26 1057 1065 3.4
## 27 1061 1057 3.4
## 28 1065 1057 3.4
## 29 1058 1062 3.8
## 30 1062 1058 3.8
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_reduced = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_fix),
p_value = median(iterated_results_table$p_fix),
R2 = NA)
model_stats_reduced %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 1.8 0.69 none
# --- REDUCED VS NULL MODEL - SHOW ΔAIC & P VALUE --- #
hist(iterated_results_table$ΔAIC_fix, main = "Distribution of ΔAIC of the reduced model.")
hist(iterated_results_table$p_fix, main = "Distribution of p-values of the reduced model.")
# --- REDUCED VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_fix) %>%
arrange(ΔAIC_fix)
## system_nr_unconnected_systems ΔAIC_fix
## 1 1059 1060 -0.5
## 2 1060 1059 -0.5
## 3 1058 1064 0.5
## 4 1064 1058 0.5
## 5 1056 1065 1.0
## 6 1058 1060 1.0
## 7 1060 1058 1.0
## 8 1065 1056 1.0
## 9 1059 1063 1.3
## 10 1063 1059 1.3
## 11 1056 1063 1.8
## 12 1057 1062 1.8
## 13 1060 1065 1.8
## 14 1062 1057 1.8
## 15 1063 1056 1.8
## 16 1065 1060 1.8
## 17 1057 1065 1.9
## 18 1062 1063 1.9
## 19 1063 1062 1.9
## 20 1065 1057 1.9
## 21 1056 1064 2.0
## 22 1057 1061 2.0
## 23 1058 1062 2.0
## 24 1059 1061 2.0
## 25 1061 1057 2.0
## 26 1061 1059 2.0
## 27 1061 1064 2.0
## 28 1062 1058 2.0
## 29 1064 1056 2.0
## 30 1064 1061 2.0
response_variable_selected = "total_metaecosystem_bioarea_mm2"
metaecosystem_type_selected = c("Medium-Medium",
"Small-Large")
Here we want to look at how this meta-ecosystem variable changed across time by plotting its mean ± 95 confidence interval:
plot.metaecos.points(ds_metaecosystems,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
plot.metaecos.replicates(ds_metaecosystems,
metaecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among meta-ecosystems. To make it easier to interpret differences, we decided to construct a model for each comparisons we are interested in, which are: SL (connected vs unconnected) and MM (connected vs unconnected).
metaecosystem_type_selected = c("Small-Large")
Our first step in the data analysis involves filtering the data to isolate the relevant data. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure we filtered data the right way.
# --- FILTER DATA --- #
filtered_data = ds_metaecosystems %>%
filter(time_point %in% time_points_model,
metaecosystem_type %in% metaecosystem_type_selected,
!is.na(!!sym("total_water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.metaecos.points(filtered_data,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same meta-ecosystem on multiple occasions, we can develop mixed effect models to examine how the connection influenced this meta-ecosystem variable. To study the effects of connection we compare two models to a null model using ANOVA: a full model and a reduced model. In all models, we treat system nr as having a random effect on how the slope and intercept of the relationship between response variable and time, with the slope and intercept being correlated (Bates et al. 2015). We also include the total water that was added due to evaporation in the microwave and the time point before the first disturbance (baseline). In the syntax of lmer4 the three models look this this:
Full model = response_variable ~connection * scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Reduced model = response_variable ~connection + scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Null model = response_variable ~scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Unconnected meta-ecosystems are made of paired unconnected
ecosystems, which are paired randomly. However, how to pair unconnected
ecosystems can be done in multiple ways, as unconnected ecosystems did
not interact and therefore any combination between ecosystems would be
arbitrary. To make sure that the random combination we selected did not
bias our results, we run all the possible combinations of ecosystems
constituting unconnected meta-ecosystems. The ecosystem combinations are
into the objects unconnected_combinations_sets (Data >
Meta-ecosystems). We therefore compute a p-value for each unconnected
ecosystems combination, creating a p-value distribution. We keep as
p-value of the comparison the median of such distributions.
# --- ADD BASELINES --- #
baselines = ds_metaecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(system_nr,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PREPARE TO COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
unconnected_combinations_sets_filtered = unconnected_combinations_sets %>%
filter(disturbance == disturbance_global_selected,
metaecosystem_type %in% metaecosystem_type_selected)
n_sets = unconnected_combinations_sets_filtered %>%
pull(set) %>%
max()
iterated_results_table = data.frame(Response = as.character(NA),
Levels = as.character(NA),
ΔAIC_full = NA,
p_full = NA,
ΔR2_full = NA,
ΔAIC_fix = NA,
p_fix = NA,
ΔR2_fix = NA,
combination_set = NA,
system_nr_unconnected_systems = as.character(NA)) %>%
slice(-1)
# --- COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
full_model_res_vs_fit = NULL
reduced_model_res_vs_fit = NULL
null_model_res_vs_fit = NULL
for (set_i in 1:n_sets) {
# Filter the data to contain all the connected meta-ecosystems and only a subset of unconnected meta-ecosystems
system_nr_unconnected_systems_input = unconnected_combinations_sets_filtered %>%
filter(metaecosystem_type %in% metaecosystem_type_selected,
connection == "unconnected",
set == set_i) %>%
pull(system_nr)
filtered_data_2 = filtered_data %>%
filter(connection == "connected" |
(connection == "unconnected" &
system_nr %in% system_nr_unconnected_systems_input))
# Construct models
full_model = try.different.optimizer.full.model()
reduced_model = try.different.optimizer.reduced.model()
null_model = try.different.optimizer.null.model()
# If all the optimisers fail, move on to the next iteration
if (is.null(full_model) || is.null(reduced_model) || is.null(null_model)) {
cat("This model could not be fitted with any optimiser. The unconnected meta-ecosystems in this iteration were:",
system_nr_unconnected_systems_input,
"\n")
next
}
if(plot_model_residuals_metaecos == TRUE){
# Plot residuals - full model
print(qqnorm(resid(full_model))); print(qqline(resid(full_model)))
#full_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, full_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(full_model),
residuals = resid(full_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_full_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - reduced model
print(qqnorm(resid(reduced_model))); print(qqline(resid(reduced_model)))
#reduced_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, reduced_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(reduced_model),
residuals = resid(reduced_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_reduced_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - null model
print(qqnorm(resid(null_model))); print(qqline(resid(null_model)))
#null_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, null_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(null_model),
residuals = resid(null_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_null_model.png")),
plot = plot,
width = 8,
height = 6)
}
# Give model statistics
model_stats_full = compute.model.stats(full_model,
null_model,
"mixed_model")
model_stats_reduced = compute.model.stats(reduced_model,
null_model,
"mixed_model")
# Save model statistics
iterated_results_table = fill.results.table(iterated_results_table,
response_variable_selected,
metaecosystem_type_selected,
model_stats_full,
model_stats_reduced)
iterated_results_table$set[nrow(iterated_results_table)] = set_i
iterated_results_table$system_nr_unconnected_systems[nrow(iterated_results_table)] =
paste(system_nr_unconnected_systems_input, collapse = " ")
}
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
Full vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_full = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_full),
p_value = median(iterated_results_table$p_full),
R2 = NA)
model_stats_full %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 -4.7 0.013 ** moderate
# --- FULL VS NULL MODEL - SHOW ΔAIC & P VALUE DISTRIBUTIONS --- #
hist(iterated_results_table$ΔAIC_full, main = "Distribution of ΔAIC of the full model.")
hist(iterated_results_table$p_full, main = "Distribution of p-values of the full model.")
# --- FULL VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_full) %>%
arrange(ΔAIC_full)
## system_nr_unconnected_systems ΔAIC_full
## 1 1027 1035 1039 1043 -7.7
## 2 1029 1035 1037 1043 -7.7
## 3 1030 1032 1039 1043 -7.6
## 4 1030 1034 1037 1043 -7.6
## 5 1027 1034 1040 1043 -7.5
## 6 1029 1032 1040 1043 -7.5
## 7 1028 1035 1039 1042 -7.2
## 8 1029 1033 1037 1045 -7.1
## 9 1027 1033 1039 1045 -7.1
## 10 1027 1034 1038 1045 -7.1
## 11 1029 1035 1038 1042 -7.0
## 12 1028 1034 1037 1045 -7.0
## 13 1030 1034 1038 1042 -6.9
## 14 1030 1033 1039 1042 -6.9
## 15 1028 1034 1040 1042 -6.9
## 16 1028 1032 1039 1045 -6.9
## 17 1029 1032 1038 1045 -6.9
## 18 1029 1033 1040 1042 -6.7
## 19 1028 1035 1037 1044 -6.7
## 20 1030 1033 1037 1044 -6.7
## 21 1027 1035 1038 1044 -6.7
## 22 1030 1032 1038 1044 -6.6
## 23 1027 1033 1040 1044 -6.6
## 24 1028 1032 1040 1044 -6.5
## 25 1030 1033 1039 1041 -6.0
## 26 1029 1033 1040 1041 -6.0
## 27 1029 1031 1040 1043 -5.9
## 28 1030 1031 1039 1043 -5.9
## 29 1028 1034 1040 1041 -5.9
## 30 1030 1034 1038 1041 -5.9
## 31 1030 1031 1038 1044 -5.8
## 32 1028 1031 1040 1044 -5.8
## 33 1028 1035 1039 1041 -5.8
## 34 1029 1035 1038 1041 -5.8
## 35 1030 1034 1036 1043 -5.7
## 36 1026 1035 1039 1043 -5.7
## 37 1026 1034 1040 1043 -5.7
## 38 1029 1031 1038 1045 -5.6
## 39 1029 1035 1036 1043 -5.6
## 40 1026 1033 1040 1044 -5.6
## 41 1026 1035 1038 1044 -5.6
## 42 1030 1033 1036 1044 -5.6
## 43 1028 1031 1039 1045 -5.6
## 44 1026 1034 1038 1045 -5.5
## 45 1026 1033 1039 1045 -5.5
## 46 1028 1035 1036 1044 -5.5
## 47 1028 1034 1036 1045 -5.4
## 48 1029 1033 1036 1045 -5.4
## 49 1030 1034 1037 1041 -5.1
## 50 1030 1031 1037 1043 -5.0
## 51 1029 1031 1037 1043 -5.0
## 52 1029 1035 1037 1041 -5.0
## 53 1030 1032 1039 1041 -5.0
## 54 1029 1033 1037 1041 -4.9
## 55 1029 1032 1036 1043 -4.9
## 56 1029 1032 1040 1041 -4.9
## 57 1027 1031 1039 1043 -4.9
## 58 1027 1035 1039 1041 -4.8
## 59 1030 1031 1037 1044 -4.7
## 60 1026 1032 1039 1043 -4.7
## 61 1026 1034 1037 1043 -4.7
## 62 1029 1031 1037 1045 -4.7
## 63 1028 1034 1037 1041 -4.7
## 64 1028 1032 1039 1041 -4.7
## 65 1027 1033 1039 1041 -4.7
## 66 1029 1032 1038 1041 -4.7
## 67 1027 1034 1040 1041 -4.7
## 68 1027 1034 1036 1043 -4.7
## 69 1030 1032 1036 1043 -4.7
## 70 1027 1031 1040 1043 -4.7
## 71 1026 1032 1039 1045 -4.6
## 72 1026 1034 1037 1045 -4.6
## 73 1030 1033 1037 1041 -4.6
## 74 1029 1032 1036 1045 -4.6
## 75 1027 1034 1036 1045 -4.6
## 76 1027 1031 1039 1045 -4.6
## 77 1026 1032 1040 1043 -4.5
## 78 1026 1035 1037 1043 -4.5
## 79 1026 1035 1037 1044 -4.5
## 80 1027 1034 1038 1041 -4.5
## 81 1027 1031 1040 1044 -4.5
## 82 1030 1032 1036 1044 -4.5
## 83 1027 1035 1036 1043 -4.5
## 84 1026 1032 1040 1044 -4.4
## 85 1026 1035 1039 1042 -4.4
## 86 1030 1031 1039 1042 -4.4
## 87 1029 1035 1036 1042 -4.4
## 88 1028 1031 1037 1044 -4.4
## 89 1030 1032 1038 1041 -4.4
## 90 1027 1035 1036 1044 -4.4
## 91 1030 1034 1036 1042 -4.3
## 92 1028 1035 1037 1041 -4.3
## 93 1028 1032 1036 1044 -4.3
## 94 1027 1031 1038 1044 -4.3
## 95 1026 1032 1038 1044 -4.2
## 96 1026 1034 1040 1042 -4.2
## 97 1029 1031 1040 1042 -4.2
## 98 1026 1033 1037 1044 -4.2
## 99 1028 1031 1037 1045 -4.2
## 100 1028 1032 1040 1041 -4.2
## 101 1027 1033 1036 1044 -4.2
## 102 1027 1033 1040 1041 -4.2
## 103 1026 1032 1038 1045 -4.1
## 104 1026 1033 1037 1045 -4.1
## 105 1028 1032 1036 1045 -4.1
## 106 1027 1033 1036 1045 -4.1
## 107 1027 1035 1038 1041 -4.1
## 108 1027 1031 1038 1045 -4.1
## 109 1029 1031 1038 1042 -3.9
## 110 1028 1031 1039 1042 -3.9
## 111 1026 1033 1039 1042 -3.8
## 112 1030 1031 1038 1042 -3.8
## 113 1028 1035 1036 1042 -3.8
## 114 1030 1033 1036 1042 -3.8
## 115 1028 1034 1036 1042 -3.8
## 116 1029 1033 1036 1042 -3.8
## 117 1026 1034 1038 1042 -3.7
## 118 1026 1035 1038 1042 -3.7
## 119 1026 1033 1040 1042 -3.6
## 120 1028 1031 1040 1042 -3.6
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_reduced = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_fix),
p_value = median(iterated_results_table$p_fix),
R2 = NA)
model_stats_reduced %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 -6 0.005 *** strong
# --- REDUCED VS NULL MODEL - SHOW ΔAIC & P VALUE --- #
hist(iterated_results_table$ΔAIC_fix, main = "Distribution of ΔAIC of the reduced model.")
hist(iterated_results_table$p_fix, main = "Distribution of p-values of the reduced model.")
# --- REDUCED VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_fix) %>%
arrange(ΔAIC_fix)
## system_nr_unconnected_systems ΔAIC_fix
## 1 1027 1035 1039 1043 -9.0
## 2 1030 1032 1039 1043 -9.0
## 3 1029 1035 1037 1043 -9.0
## 4 1030 1034 1037 1043 -8.9
## 5 1029 1032 1040 1043 -8.9
## 6 1027 1034 1040 1043 -8.7
## 7 1028 1035 1039 1042 -8.4
## 8 1029 1035 1038 1042 -8.3
## 9 1030 1034 1038 1042 -8.1
## 10 1030 1033 1039 1042 -8.1
## 11 1028 1034 1040 1042 -8.1
## 12 1029 1033 1040 1042 -7.9
## 13 1027 1033 1039 1045 -7.9
## 14 1029 1033 1037 1045 -7.8
## 15 1028 1034 1037 1045 -7.8
## 16 1027 1034 1038 1045 -7.8
## 17 1028 1032 1039 1045 -7.7
## 18 1029 1032 1038 1045 -7.7
## 19 1030 1033 1037 1044 -7.6
## 20 1028 1035 1037 1044 -7.5
## 21 1027 1035 1038 1044 -7.5
## 22 1028 1032 1040 1044 -7.4
## 23 1030 1032 1038 1044 -7.4
## 24 1027 1033 1040 1044 -7.4
## 25 1029 1035 1037 1041 -6.8
## 26 1030 1034 1037 1041 -6.8
## 27 1030 1032 1039 1041 -6.8
## 28 1029 1032 1040 1041 -6.7
## 29 1029 1031 1037 1043 -6.6
## 30 1027 1035 1039 1041 -6.6
## 31 1030 1031 1037 1043 -6.5
## 32 1029 1032 1036 1043 -6.5
## 33 1027 1034 1040 1041 -6.5
## 34 1027 1031 1039 1043 -6.5
## 35 1030 1031 1037 1044 -6.4
## 36 1029 1033 1037 1041 -6.4
## 37 1026 1032 1039 1043 -6.3
## 38 1026 1034 1037 1043 -6.3
## 39 1027 1034 1036 1043 -6.3
## 40 1030 1032 1036 1043 -6.3
## 41 1027 1031 1040 1043 -6.3
## 42 1029 1031 1037 1045 -6.2
## 43 1028 1034 1037 1041 -6.2
## 44 1028 1032 1039 1041 -6.2
## 45 1027 1033 1039 1041 -6.2
## 46 1029 1032 1038 1041 -6.2
## 47 1029 1032 1036 1045 -6.2
## 48 1027 1031 1039 1045 -6.2
## 49 1030 1032 1036 1044 -6.2
## 50 1026 1035 1037 1043 -6.1
## 51 1026 1035 1037 1044 -6.1
## 52 1026 1032 1039 1045 -6.1
## 53 1026 1034 1037 1045 -6.1
## 54 1026 1035 1039 1042 -6.1
## 55 1027 1034 1036 1045 -6.1
## 56 1027 1031 1040 1044 -6.1
## 57 1026 1032 1040 1043 -6.0
## 58 1026 1032 1040 1044 -6.0
## 59 1030 1031 1039 1042 -6.0
## 60 1030 1034 1036 1042 -6.0
## 61 1029 1035 1036 1042 -6.0
## 62 1030 1033 1037 1041 -6.0
## 63 1027 1035 1036 1044 -6.0
## 64 1027 1035 1036 1043 -6.0
## 65 1026 1034 1040 1042 -5.9
## 66 1029 1031 1040 1042 -5.9
## 67 1027 1034 1038 1041 -5.9
## 68 1028 1031 1037 1044 -5.7
## 69 1030 1032 1038 1041 -5.7
## 70 1028 1035 1037 1041 -5.6
## 71 1028 1032 1040 1041 -5.6
## 72 1027 1033 1040 1041 -5.6
## 73 1026 1033 1037 1044 -5.5
## 74 1028 1032 1036 1044 -5.5
## 75 1027 1033 1036 1044 -5.5
## 76 1027 1031 1038 1044 -5.5
## 77 1026 1032 1038 1044 -5.4
## 78 1027 1035 1038 1041 -5.4
## 79 1028 1031 1037 1045 -5.2
## 80 1028 1031 1039 1042 -5.2
## 81 1026 1032 1038 1045 -5.1
## 82 1029 1031 1038 1042 -5.1
## 83 1026 1033 1037 1045 -5.1
## 84 1028 1034 1036 1042 -5.1
## 85 1028 1032 1036 1045 -5.1
## 86 1027 1033 1036 1045 -5.1
## 87 1027 1031 1038 1045 -5.1
## 88 1026 1034 1038 1042 -5.0
## 89 1026 1033 1039 1042 -5.0
## 90 1026 1035 1038 1042 -5.0
## 91 1028 1035 1036 1042 -5.0
## 92 1029 1033 1036 1042 -5.0
## 93 1030 1031 1038 1042 -4.9
## 94 1028 1031 1040 1042 -4.9
## 95 1030 1033 1036 1042 -4.9
## 96 1026 1033 1040 1042 -4.8
## 97 1026 1035 1039 1043 -4.7
## 98 1029 1031 1040 1043 -4.6
## 99 1030 1031 1039 1043 -4.6
## 100 1026 1034 1040 1043 -4.6
## 101 1029 1035 1036 1043 -4.5
## 102 1030 1034 1036 1043 -4.4
## 103 1028 1034 1040 1041 -4.3
## 104 1028 1035 1039 1041 -4.3
## 105 1030 1033 1039 1041 -4.1
## 106 1030 1034 1038 1041 -4.1
## 107 1029 1035 1038 1041 -4.1
## 108 1029 1033 1040 1041 -4.1
## 109 1026 1035 1038 1044 -3.9
## 110 1028 1031 1040 1044 -3.9
## 111 1028 1035 1036 1044 -3.8
## 112 1026 1033 1040 1044 -3.7
## 113 1030 1031 1038 1044 -3.7
## 114 1030 1033 1036 1044 -3.4
## 115 1026 1034 1038 1045 -3.3
## 116 1028 1031 1039 1045 -3.3
## 117 1029 1031 1038 1045 -3.2
## 118 1026 1033 1039 1045 -3.2
## 119 1028 1034 1036 1045 -3.1
## 120 1029 1033 1036 1045 -2.9
metaecosystem_type_selected = c("Medium-Medium")
Our first step in the data analysis involves filtering the data to isolate the relevant data. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure we filtered data the right way.
# --- FILTER DATA --- #
filtered_data = ds_metaecosystems %>%
filter(time_point %in% time_points_model,
metaecosystem_type %in% metaecosystem_type_selected,
!is.na(!!sym("total_water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.metaecos.points(filtered_data,
metaecosystem_type_selected,
connection_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same meta-ecosystem on multiple occasions, we can develop mixed effect models to examine how the connection influenced this meta-ecosystem variable. To study the effects of connection we compare two models to a null model using ANOVA: a full model and a reduced model. In all models, we treat system nr as having a random effect on how the slope and intercept of the relationship between response variable and time, with the slope and intercept being correlated (Bates et al. 2015). We also include the total water that was added due to evaporation in the microwave and the time point before the first disturbance (baseline). In the syntax of lmer4 the three models look this this:
Full model = response_variable ~connection * scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Reduced model = response_variable ~connection + scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Null model = response_variable ~scale(day) + scale(total_water_addition_ml) * scale(day) + scale(baseline) * scale(day) + (day | system_nr)
Unconnected meta-ecosystems are made of paired unconnected
ecosystems, which are paired randomly. However, how to pair unconnected
ecosystems can be done in multiple ways, as unconnected ecosystems did
not interact and therefore any combination between ecosystems would be
arbitrary. To make sure that the random combination we selected did not
bias our results, we run all the possible combinations of ecosystems
constituting unconnected meta-ecosystems. The ecosystem combinations are
into the objects unconnected_combinations_sets (Data >
Meta-ecosystems). We therefore compute a p-value for each unconnected
ecosystems combination, creating a p-value distribution. We keep as
p-value of the comparison the median of such distributions.
# --- ADD BASELINES --- #
baselines = ds_metaecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(system_nr,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PREPARE TO COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
unconnected_combinations_sets_filtered = unconnected_combinations_sets %>%
filter(disturbance == disturbance_global_selected,
metaecosystem_type %in% metaecosystem_type_selected)
n_sets = unconnected_combinations_sets_filtered %>%
pull(set) %>%
max()
iterated_results_table = data.frame(Response = as.character(NA),
Levels = as.character(NA),
ΔAIC_full = NA,
p_full = NA,
ΔR2_full = NA,
ΔAIC_fix = NA,
p_fix = NA,
ΔR2_fix = NA,
combination_set = NA,
system_nr_unconnected_systems = as.character(NA)) %>%
slice(-1)
# --- COMPARE FULL, REDUCED, AND NULL MODEL WHILE RESHUFFLING ECOSYSTEM COMBINATIONS --- #
full_model_res_vs_fit = NULL
reduced_model_res_vs_fit = NULL
null_model_res_vs_fit = NULL
for (set_i in 1:n_sets) {
# Filter the data to contain all the connected meta-ecosystems and only a subset of unconnected meta-ecosystems
system_nr_unconnected_systems_input = unconnected_combinations_sets_filtered %>%
filter(metaecosystem_type %in% metaecosystem_type_selected,
connection == "unconnected",
set == set_i) %>%
pull(system_nr)
filtered_data_2 = filtered_data %>%
filter(connection == "connected" |
(connection == "unconnected" &
system_nr %in% system_nr_unconnected_systems_input))
# Construct models
full_model = try.different.optimizer.full.model()
reduced_model = try.different.optimizer.reduced.model()
null_model = try.different.optimizer.null.model()
# If all the optimisers fail, move on to the next iteration
if (is.null(full_model) || is.null(reduced_model) || is.null(null_model)) {
cat("This model could not be fitted with any optimiser. The unconnected meta-ecosystems in this iteration were:",
system_nr_unconnected_systems_input,
"\n")
next
}
if(plot_model_residuals_metaecos == TRUE){
# Plot residuals - full model
print(qqnorm(resid(full_model))); print(qqline(resid(full_model)))
#full_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, full_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(full_model),
residuals = resid(full_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_full_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - reduced model
print(qqnorm(resid(reduced_model))); print(qqline(resid(reduced_model)))
#reduced_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, reduced_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(reduced_model),
residuals = resid(reduced_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_reduced_model.png")),
plot = plot,
width = 8,
height = 6)
# Plot residuals - null model
print(qqnorm(resid(null_model))); print(qqline(resid(null_model)))
#null_model_res_vs_fit[[set_i]] = create.res.vs.fit.metaecos(filtered_data_2, null_model)
plot = filtered_data_2 %>%
mutate(predicted = fitted(null_model),
residuals = resid(null_model)) %>%
ggplot(aes(x = predicted,
y = residuals)) +
geom_point()
ggsave(here("6_results",
"residual_plots",
paste0(disturbance_global_selected,
"_disturbance_",
gsub(pattern = " ", replacement = "", metaecosystem_type_selected[[1]]),
"_",
response_variable_selected,
"_",
set_i,
"_null_model.png")),
plot = plot,
width = 8,
height = 6)
}
# Give model statistics
model_stats_full = compute.model.stats(full_model,
null_model,
"mixed_model")
model_stats_reduced = compute.model.stats(reduced_model,
null_model,
"mixed_model")
# Save model statistics
iterated_results_table = fill.results.table(iterated_results_table,
response_variable_selected,
metaecosystem_type_selected,
model_stats_full,
model_stats_reduced)
iterated_results_table$set[nrow(iterated_results_table)] = set_i
iterated_results_table$system_nr_unconnected_systems[nrow(iterated_results_table)] =
paste(system_nr_unconnected_systems_input, collapse = " ")
}
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: optimx (L-BFGS-B)"
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
## [1] "Model successfully fitted with optimizer: bobyqa "
Full vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_full = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_full),
p_value = median(iterated_results_table$p_full),
R2 = NA)
model_stats_full %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 3.3 0.705 none
# --- FULL VS NULL MODEL - SHOW ΔAIC & P VALUE DISTRIBUTIONS --- #
hist(iterated_results_table$ΔAIC_full, main = "Distribution of ΔAIC of the full model.")
hist(iterated_results_table$p_full, main = "Distribution of p-values of the full model.")
# --- FULL VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_full) %>%
arrange(ΔAIC_full)
## system_nr_unconnected_systems ΔAIC_full
## 1 1056 1065 1.4
## 2 1065 1056 1.4
## 3 1058 1062 1.5
## 4 1059 1061 1.5
## 5 1061 1059 1.5
## 6 1062 1058 1.5
## 7 1058 1060 3.0
## 8 1060 1058 3.0
## 9 1057 1061 3.1
## 10 1061 1057 3.1
## 11 1056 1063 3.2
## 12 1063 1056 3.2
## 13 1057 1065 3.3
## 14 1058 1064 3.3
## 15 1064 1058 3.3
## 16 1065 1057 3.3
## 17 1059 1063 3.4
## 18 1063 1059 3.4
## 19 1060 1065 3.5
## 20 1065 1060 3.5
## 21 1061 1064 3.6
## 22 1062 1063 3.6
## 23 1063 1062 3.6
## 24 1064 1061 3.6
## 25 1059 1060 3.7
## 26 1060 1059 3.7
## 27 1056 1064 3.8
## 28 1057 1062 3.8
## 29 1062 1057 3.8
## 30 1064 1056 3.8
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
model_stats_reduced = data.frame(deltaAIC = median(iterated_results_table$ΔAIC_fix),
p_value = median(iterated_results_table$p_fix),
R2 = NA)
model_stats_reduced %>%
mutate(deltaAIC = round(deltaAIC, digits = 1),
p_value = round(p_value, digits = 3),
R2 = NULL,
evidence = "",
evidence = ifelse(p_value > 0.1,
"none",
evidence),
evidence = ifelse(p_value < 0.1,
"* weak",
evidence),
evidence = ifelse(p_value < 0.05,
"** moderate",
evidence),
evidence = ifelse(p_value < 0.01,
"*** strong",
evidence),
evidence = ifelse(p_value < 0.001,
"**** very strong",
evidence),
p_value = ifelse(p_value < 0.001,
"< 0.001",
p_value)) %>%
print()
## deltaAIC p_value evidence
## 1 2 0.918 none
# --- REDUCED VS NULL MODEL - SHOW ΔAIC & P VALUE --- #
hist(iterated_results_table$ΔAIC_fix, main = "Distribution of ΔAIC of the reduced model.")
hist(iterated_results_table$p_fix, main = "Distribution of p-values of the reduced model.")
# --- REDUCED VS NULL MODEL - SHOW WHICH UNCONNECTED META-ECOSYSTEM NUMBER PRODUCD WHICH AIC --- #
iterated_results_table %>%
select(system_nr_unconnected_systems,
ΔAIC_fix) %>%
arrange(ΔAIC_fix)
## system_nr_unconnected_systems ΔAIC_fix
## 1 1056 1065 0.5
## 2 1065 1056 0.5
## 3 1058 1062 0.6
## 4 1059 1061 0.6
## 5 1061 1059 0.6
## 6 1062 1058 0.6
## 7 1056 1063 1.8
## 8 1063 1056 1.8
## 9 1062 1063 1.9
## 10 1063 1062 1.9
## 11 1056 1064 2.0
## 12 1057 1061 2.0
## 13 1057 1062 2.0
## 14 1057 1065 2.0
## 15 1058 1060 2.0
## 16 1058 1064 2.0
## 17 1059 1060 2.0
## 18 1059 1063 2.0
## 19 1060 1058 2.0
## 20 1060 1059 2.0
## 21 1060 1065 2.0
## 22 1061 1057 2.0
## 23 1061 1064 2.0
## 24 1062 1057 2.0
## 25 1063 1059 2.0
## 26 1064 1056 2.0
## 27 1064 1058 2.0
## 28 1064 1061 2.0
## 29 1065 1057 2.0
## 30 1065 1060 2.0
ecosystem_type_selected = c("Small unconnected",
"Medium unconnected",
"Large unconnected",
"Small connected to small",
"Small connected to large",
"Medium connected to medium",
"Large connected to small",
"Large connected to large")
ds_ecosystems %>%
filter(is.na(species_richness) != TRUE) %>%
ggplot(aes(x = species_richness,
y = bioarea_mm2_per_ml)) +
geom_point() +
xlim(0, length(protist_species)) +
labs(x = axis_names$axis_name[axis_names$variable == "species_richness"],
y = axis_names$axis_name[axis_names$variable == "bioarea_mm2_per_ml"]) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position,
legend.key.width = unit(legend_width_cm, "cm"))
ds_ecosystems %>%
filter(is.na(shannon) != TRUE) %>%
ggplot(aes(x = shannon,
y = bioarea_mm2_per_ml)) +
geom_point() +
labs(x = axis_names$axis_name[axis_names$variable == "shannon"],
y = axis_names$axis_name[axis_names$variable == "bioarea_mm2_per_ml"]) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position,
legend.key.width = unit(legend_width_cm, "cm"))
ds_ecosystems %>%
filter(is.na(evenness_pielou) != TRUE) %>%
ggplot(aes(x = evenness_pielou,
y = bioarea_mm2_per_ml)) +
geom_point() +
labs(x = axis_names$axis_name[axis_names$variable == "evenness_pielou"],
y = axis_names$axis_name[axis_names$variable == "bioarea_mm2_per_ml"]) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position,
legend.key.width = unit(legend_width_cm, "cm"))
response_variable = "water_addition_ml"
UNLIKE ALL THE OTHER ANALYSIS, THIS INCLUDES BOTH DISTURBANCE LEVELS.
We want to know whether the size of an ecosystem influenced its evaporation rate. We first start from plotting how the water that was added to the cultures changed across size through its mean ± 95 confidence interval:
# --- FILTER DATASET --- #
ds_ecosystems_both_disturbances_filtered = ds_ecosystems_both_disturbances %>%
filter(!is.na(water_addition_ml)) %>%
mutate(sqrt_water_addition_ml = sqrt(water_addition_ml),
log_water_addition_ml = log(water_addition_ml),
inv_water_addition_ml = 1 / water_addition_ml)
# --- PLOT WATER ADDITION MEAN ± 95 CI --- #
ds_ecosystems_both_disturbances_filtered %>%
summarySE(measurevar = response_variable,
groupvars = c("day", "ecosystem_size")) %>%
ggplot(aes(x = day,
y = get(response_variable),
group = interaction(day, ecosystem_size),
color = ecosystem_size)) +
geom_point(stat = "summary",
fun = "mean",
position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(stat = "summary",
fun = "mean",
aes(group = ecosystem_size),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
geom_errorbar(aes(ymax = get(response_variable) + ci,
ymin = get(response_variable) - ci),
width = width_errorbar,
position = position_dodge(dodging)) +
labs(x = "Day",
y = "Water addition (ml)",
color = "") +
scale_x_continuous(breaks = unique(ds_ecosystems$day)) +
geom_vline(xintercept = resource_flow_days,
linetype = resource_flow_line_type,
color = resource_flow_line_colour,
linewidth = resource_flow_line_width) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position) +
scale_color_manual(values = c("#000000", "#737373", "#bdbdbd")) +
geom_rect(xmin = grey_background_xmin,
xmax = grey_background_xmax,
ymin = grey_background_ymin,
ymax = grey_background_ymax,
fill = grey_background_fill,
alpha = grey_background_alpha,
color = grey_background_color)
# --- PLOT WATER ADDITION SINGLE REPLICATES --- #
ds_ecosystems_both_disturbances_filtered %>%
ggplot(aes(x = day,
y = get(response_variable),
group = interaction(culture_ID, day),
color = ecosystem_size)) +
geom_point() +
geom_line(aes(group = culture_ID)) +
scale_x_continuous(breaks = unique(ds_ecosystems$day)) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position) +
geom_rect(xmin = grey_background_xmin,
xmax = grey_background_xmax,
ymin = grey_background_ymin,
ymax = grey_background_ymax,
fill = grey_background_fill,
alpha = grey_background_alpha,
color = grey_background_color) +
labs(x = "Day",
y = "Water addition (ml)",
color = "") +
scale_color_manual(values = c("#000000", "#737373", "#bdbdbd"))
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable) ~
ecosystem_size +
(1 | time_point),
data = ds_ecosystems_both_disturbances_filtered,
REML = FALSE)
null_model = lmer(get(response_variable) ~
(1 | time_point),
data = ds_ecosystems_both_disturbances_filtered,
REML = FALSE)
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -4.7 0.013 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
print(create.res.vs.fit.ecos(ds_ecosystems_both_disturbances_filtered, full_model))
qqnorm(resid(full_model))
qqline(resid(full_model))
ecosystem_type_selected = c("Small unconnected",
"Medium unconnected",
"Large unconnected")
response_variable_selected = "shannon"
We want to know whether the size of ecosystems influenced this response variable. We only look at unconnected ecosystems so that the effects of connection don’t confound the effects of ecosystem size. We first start from plotting how this response variable changed in different sizes throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(metaecosystem == "no",
time_point %in% time_points_model,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- CALCULATE BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines,
!is.na(!!sym(response_variable_selected))) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how ecosystem size influenced this variable. To study the
effects of ecosystem size we compare two models to a null model using
ANOVA: a full model and a reduced model. In all models, we treat culture
ID as having a random effect on how the slope and intercept of the
relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of size with time
(Response variable ~ size * day + (day | culture ID)), the
reduced model contains the size but without the interaction with time
(Response variable ~ size + day + (day | culture ID)), and
the null model doesn’t contain the size at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem size had an
effect.
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_size * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_size +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -34.1 < 0.001 **** very strong
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -32.6 < 0.001 **** very strong
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "bioarea_mm2_per_ml"
We want to know whether the size of ecosystems influenced this response variable. We only look at unconnected ecosystems so that the effects of connection don’t confound the effects of ecosystem size. We first start from plotting how this response variable changed in different sizes throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(metaecosystem == "no",
time_point %in% time_points_model,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- CALCULATE BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines,
!is.na(!!sym(response_variable_selected))) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how ecosystem size influenced this variable. To study the
effects of ecosystem size we compare two models to a null model using
ANOVA: a full model and a reduced model. In all models, we treat culture
ID as having a random effect on how the slope and intercept of the
relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of size with time
(Response variable ~ size * day + (day | culture ID)), the
reduced model contains the size but without the interaction with time
(Response variable ~ size + day + (day | culture ID)), and
the null model doesn’t contain the size at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem size had an
effect.
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_size * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_size +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -30.1 < 0.001 **** very strong
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -6.8 0.004 *** strong
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "species_richness"
We want to know whether the size of ecosystems influenced this response variable. We only look at unconnected ecosystems so that the effects of connection don’t confound the effects of ecosystem size. We first start from plotting how this response variable changed in different sizes throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(metaecosystem == "no",
time_point %in% time_points_model,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- CALCULATE BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines,
!is.na(!!sym(response_variable_selected))) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how ecosystem size influenced this variable. To study the
effects of ecosystem size we compare two models to a null model using
ANOVA: a full model and a reduced model. In all models, we treat culture
ID as having a random effect on how the slope and intercept of the
relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of size with time
(Response variable ~ size * day + (day | culture ID)), the
reduced model contains the size but without the interaction with time
(Response variable ~ size + day + (day | culture ID)), and
the null model doesn’t contain the size at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem size had an
effect.
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_size * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_size +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.00248252 (tol = 0.002, component 1)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -43.1 < 0.001 **** very strong
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -44.9 < 0.001 **** very strong
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "evenness_pielou"
We want to know whether the size of ecosystems influenced this response variable. We only look at unconnected ecosystems so that the effects of connection don’t confound the effects of ecosystem size. We first start from plotting how this response variable changed in different sizes throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(metaecosystem == "no",
time_point %in% time_points_model,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- CALCULATE BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines,
!is.na(!!sym(response_variable_selected))) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how ecosystem size influenced this variable. To study the
effects of ecosystem size we compare two models to a null model using
ANOVA: a full model and a reduced model. In all models, we treat culture
ID as having a random effect on how the slope and intercept of the
relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of size with time
(Response variable ~ size * day + (day | culture ID)), the
reduced model contains the size but without the interaction with time
(Response variable ~ size + day + (day | culture ID)), and
the null model doesn’t contain the size at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem size had an
effect.
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_size * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_size +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -35.2 < 0.001 **** very strong
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -22.6 < 0.001 **** very strong
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "median_body_area_µm2"
We want to know whether the size of ecosystems influenced this response variable. We only look at unconnected ecosystems so that the effects of connection don’t confound the effects of ecosystem size. We first start from plotting how this response variable changed in different sizes throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(metaecosystem == "no",
time_point %in% time_points_model,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- CALCULATE BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines,
!is.na(!!sym(response_variable_selected))) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how ecosystem size influenced this variable. To study the
effects of ecosystem size we compare two models to a null model using
ANOVA: a full model and a reduced model. In all models, we treat culture
ID as having a random effect on how the slope and intercept of the
relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of size with time
(Response variable ~ size * day + (day | culture ID)), the
reduced model contains the size but without the interaction with time
(Response variable ~ size + day + (day | culture ID)), and
the null model doesn’t contain the size at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem size had an
effect.
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_size * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_size +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -4.3 0.015 ** moderate
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -5.8 0.007 *** strong
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "auto_hetero_ratio"
We want to know whether the size of ecosystems influenced this response variable. We only look at unconnected ecosystems so that the effects of connection don’t confound the effects of ecosystem size. We first start from plotting how this response variable changed in different sizes throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(metaecosystem == "no",
time_point %in% time_points_model,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- CALCULATE BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines,
!is.na(!!sym(response_variable_selected))) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how ecosystem size influenced this variable. To study the
effects of ecosystem size we compare two models to a null model using
ANOVA: a full model and a reduced model. In all models, we treat culture
ID as having a random effect on how the slope and intercept of the
relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of size with time
(Response variable ~ size * day + (day | culture ID)), the
reduced model contains the size but without the interaction with time
(Response variable ~ size + day + (day | culture ID)), and
the null model doesn’t contain the size at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem size had an
effect.
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_size * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_size +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -6.9 0.005 *** strong
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -1.5 0.062 * weak
# --- SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
for(eco_type_i in 1:length(ecosystem_type_selected)){
print(ecosystem_type_selected[eco_type_i])
p = ds_ecosystems %>%
filter(ecosystem_type == ecosystem_type_selected[eco_type_i]) %>%
group_by(day) %>%
summarise(
Ble = mean(Ble_indiv_per_ml_dominance, na.rm = TRUE),
# Ble_se = sd(Ble_indiv_per_ml_dominance, na.rm = TRUE) / sqrt(n()),
# Ble_ci = qt(c(0.025, 0.975), df = n() - 1) * Ble_se,
Cep = mean(Cep_indiv_per_ml_dominance, na.rm = TRUE),
Col = mean(Col_indiv_per_ml_dominance, na.rm = TRUE),
Eug = mean(Eug_indiv_per_ml_dominance, na.rm = TRUE),
Eup = mean(Eup_indiv_per_ml_dominance, na.rm = TRUE),
Lox = mean(Lox_indiv_per_ml_dominance, na.rm = TRUE),
Pau = mean(Pau_indiv_per_ml_dominance, na.rm = TRUE),
Pca = mean(Pca_indiv_per_ml_dominance, na.rm = TRUE),
Spi = mean(Spi_indiv_per_ml_dominance, na.rm = TRUE),
Spi_te = mean(Spi_te_indiv_per_ml_dominance, na.rm = TRUE),
Tet = mean(Tet_indiv_per_ml_dominance, na.rm = TRUE)
) %>%
pivot_longer(Ble:Tet, names_to = "species", values_to = "species_indiv_per_ml") %>%
ggplot(aes(
x = day,
y = species_indiv_per_ml,
group = interaction(day, species),
color = species
)) +
geom_point(position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(
aes(group = species),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
labs(x = axis_names %>%
filter(variable == "day") %>%
pull(axis_name),
y = axis_names %>%
filter(variable == "dominance") %>%
pull(axis_name)) +
coord_cartesian(ylim = c(0, 100))
print(p)
}
## [1] "Small unconnected"
## [1] "Medium unconnected"
## [1] "Large unconnected"
response_variable = "water_addition_ml"
UNLIKE ALL THE OTHER ANALYSIS, THIS INCLUDES BOTH DISTURBANCE LEVELS.
We want to know whether the size of an ecosystem influenced its evaporation rate. We first start from plotting how the water that was added to the cultures changed across size through its mean ± 95 confidence interval:
# --- FILTER DATASET --- #
ds_ecosystems_both_disturbances_filtered = ds_ecosystems_both_disturbances %>%
filter(!is.na(water_addition_ml)) %>%
mutate(sqrt_water_addition_ml = sqrt(water_addition_ml),
log_water_addition_ml = log(water_addition_ml),
inv_water_addition_ml = 1 / water_addition_ml)
# --- PLOT WATER ADDITION MEAN ± 95 CI --- #
ds_ecosystems_both_disturbances_filtered %>%
summarySE(measurevar = response_variable,
groupvars = c("day", "ecosystem_size")) %>%
ggplot(aes(x = day,
y = get(response_variable),
group = interaction(day, ecosystem_size),
color = ecosystem_size)) +
geom_point(stat = "summary",
fun = "mean",
position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(stat = "summary",
fun = "mean",
aes(group = ecosystem_size),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
geom_errorbar(aes(ymax = get(response_variable) + ci,
ymin = get(response_variable) - ci),
width = width_errorbar,
position = position_dodge(dodging)) +
labs(x = "Day",
y = "Water addition (ml)",
color = "") +
scale_x_continuous(breaks = unique(ds_ecosystems$day)) +
geom_vline(xintercept = resource_flow_days,
linetype = resource_flow_line_type,
color = resource_flow_line_colour,
linewidth = resource_flow_line_width) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position) +
scale_color_manual(values = c("#000000", "#737373", "#bdbdbd")) +
geom_rect(xmin = grey_background_xmin,
xmax = grey_background_xmax,
ymin = grey_background_ymin,
ymax = grey_background_ymax,
fill = grey_background_fill,
alpha = grey_background_alpha,
color = grey_background_color)
# --- PLOT WATER ADDITION SINGLE REPLICATES --- #
ds_ecosystems_both_disturbances_filtered %>%
ggplot(aes(x = day,
y = get(response_variable),
group = interaction(culture_ID, day),
color = ecosystem_size)) +
geom_point() +
geom_line(aes(group = culture_ID)) +
scale_x_continuous(breaks = unique(ds_ecosystems$day)) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position) +
geom_rect(xmin = grey_background_xmin,
xmax = grey_background_xmax,
ymin = grey_background_ymin,
ymax = grey_background_ymax,
fill = grey_background_fill,
alpha = grey_background_alpha,
color = grey_background_color) +
labs(x = "Day",
y = "Water addition (ml)",
color = "") +
scale_color_manual(values = c("#000000", "#737373", "#bdbdbd"))
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable) ~
ecosystem_size +
(1 | time_point),
data = ds_ecosystems_both_disturbances_filtered,
REML = FALSE)
null_model = lmer(get(response_variable) ~
(1 | time_point),
data = ds_ecosystems_both_disturbances_filtered,
REML = FALSE)
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -4.7 0.013 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
print(create.res.vs.fit.ecos(ds_ecosystems_both_disturbances_filtered, full_model))
qqnorm(resid(full_model))
qqline(resid(full_model))
ecosystem_type_selected = c("Small connected to large",
"Small unconnected")
response_variable_selected = "shannon"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -3.4 0.025 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -4.2 0.013 ** moderate
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "bioarea_mm2_per_ml"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -5.2 0.01 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -1.3 0.07 * weak
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "species_richness"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -9.5 0.001 *** strong
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -10 0.001 *** strong
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "evenness_pielou"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -25.6 < 0.001 **** very strong
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -22.8 < 0.001 **** very strong
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "median_body_area_µm2"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning: Model failed to converge with 1 negative eigenvalue: -6.4e-02
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 2.5 0.477 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 0.5 0.224 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
for(eco_type_i in 1:length(ecosystem_type_selected)){
print(ecosystem_type_selected[eco_type_i])
p = ds_ecosystems %>%
filter(ecosystem_type == ecosystem_type_selected[eco_type_i]) %>%
group_by(day) %>%
summarise(
Ble = mean(Ble_indiv_per_ml_dominance, na.rm = TRUE),
# Ble_se = sd(Ble_indiv_per_ml_dominance, na.rm = TRUE) / sqrt(n()),
# Ble_ci = qt(c(0.025, 0.975), df = n() - 1) * Ble_se,
Cep = mean(Cep_indiv_per_ml_dominance, na.rm = TRUE),
Col = mean(Col_indiv_per_ml_dominance, na.rm = TRUE),
Eug = mean(Eug_indiv_per_ml_dominance, na.rm = TRUE),
Eup = mean(Eup_indiv_per_ml_dominance, na.rm = TRUE),
Lox = mean(Lox_indiv_per_ml_dominance, na.rm = TRUE),
Pau = mean(Pau_indiv_per_ml_dominance, na.rm = TRUE),
Pca = mean(Pca_indiv_per_ml_dominance, na.rm = TRUE),
Spi = mean(Spi_indiv_per_ml_dominance, na.rm = TRUE),
Spi_te = mean(Spi_te_indiv_per_ml_dominance, na.rm = TRUE),
Tet = mean(Tet_indiv_per_ml_dominance, na.rm = TRUE)
) %>%
pivot_longer(Ble:Tet, names_to = "species", values_to = "species_indiv_per_ml") %>%
ggplot(aes(
x = day,
y = species_indiv_per_ml,
group = interaction(day, species),
color = species
)) +
geom_point(position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(
aes(group = species),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
labs(x = axis_names %>%
filter(variable == "day") %>%
pull(axis_name),
y = axis_names %>%
filter(variable == "dominance") %>%
pull(axis_name)) +
coord_cartesian(ylim = c(0, 100))
print(p)
}
## [1] "Small connected to large"
## [1] "Small unconnected"
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
"water_addition_ml")
ecosystem_type_selected = c("Small connected to large",
"Small connected to small")
response_variable_selected = "shannon"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 0.9 0.208 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -1.1 0.079 * weak
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "bioarea_mm2_per_ml"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 2.2 0.409 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 0.2 0.183 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "species_richness"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -2 0.049 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -4 0.014 ** moderate
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "evenness_pielou"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -4 0.018 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -0.9 0.089 * weak
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "median_body_area_µm2"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.0620832 (tol = 0.002, component 1)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.0439227 (tol = 0.002, component 1)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.00726836 (tol = 0.002, component 1)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -3.8 0.02 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -1.9 0.048 ** moderate
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
for(eco_type_i in 1:length(ecosystem_type_selected)){
print(ecosystem_type_selected[eco_type_i])
p = ds_ecosystems %>%
filter(ecosystem_type == ecosystem_type_selected[eco_type_i]) %>%
group_by(day) %>%
summarise(
Ble = mean(Ble_indiv_per_ml_dominance, na.rm = TRUE),
# Ble_se = sd(Ble_indiv_per_ml_dominance, na.rm = TRUE) / sqrt(n()),
# Ble_ci = qt(c(0.025, 0.975), df = n() - 1) * Ble_se,
Cep = mean(Cep_indiv_per_ml_dominance, na.rm = TRUE),
Col = mean(Col_indiv_per_ml_dominance, na.rm = TRUE),
Eug = mean(Eug_indiv_per_ml_dominance, na.rm = TRUE),
Eup = mean(Eup_indiv_per_ml_dominance, na.rm = TRUE),
Lox = mean(Lox_indiv_per_ml_dominance, na.rm = TRUE),
Pau = mean(Pau_indiv_per_ml_dominance, na.rm = TRUE),
Pca = mean(Pca_indiv_per_ml_dominance, na.rm = TRUE),
Spi = mean(Spi_indiv_per_ml_dominance, na.rm = TRUE),
Spi_te = mean(Spi_te_indiv_per_ml_dominance, na.rm = TRUE),
Tet = mean(Tet_indiv_per_ml_dominance, na.rm = TRUE)
) %>%
pivot_longer(Ble:Tet, names_to = "species", values_to = "species_indiv_per_ml") %>%
ggplot(aes(
x = day,
y = species_indiv_per_ml,
group = interaction(day, species),
color = species
)) +
geom_point(position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(
aes(group = species),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
labs(x = axis_names %>%
filter(variable == "day") %>%
pull(axis_name),
y = axis_names %>%
filter(variable == "dominance") %>%
pull(axis_name)) +
coord_cartesian(ylim = c(0, 100))
print(p)
}
## [1] "Small connected to large"
## [1] "Small connected to small"
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
"water_addition_ml")
ecosystem_type_selected = c("Small connected to small",
"Small unconnected")
response_variable_selected = "shannon"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.0511897 (tol = 0.002, component 1)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.112773 (tol = 0.002, component 1)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.00409627 (tol = 0.002, component 1)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -3.9 0.019 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -4.7 0.01 ** moderate
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "bioarea_mm2_per_ml"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -3.4 0.024 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -1.5 0.062 * weak
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "species_richness"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.0120985 (tol = 0.002, component 1)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.0674878 (tol = 0.002, component 1)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.0425663 (tol = 0.002, component 1)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -6.4 0.006 *** strong
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -6.6 0.003 *** strong
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "evenness_pielou"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -2.5 0.038 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -4 0.014 ** moderate
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "median_body_area_µm2"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 1.7 0.324 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 0.8 0.264 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
for(eco_type_i in 1:length(ecosystem_type_selected)){
print(ecosystem_type_selected[eco_type_i])
p = ds_ecosystems %>%
filter(ecosystem_type == ecosystem_type_selected[eco_type_i]) %>%
group_by(day) %>%
summarise(
Ble = mean(Ble_indiv_per_ml_dominance, na.rm = TRUE),
# Ble_se = sd(Ble_indiv_per_ml_dominance, na.rm = TRUE) / sqrt(n()),
# Ble_ci = qt(c(0.025, 0.975), df = n() - 1) * Ble_se,
Cep = mean(Cep_indiv_per_ml_dominance, na.rm = TRUE),
Col = mean(Col_indiv_per_ml_dominance, na.rm = TRUE),
Eug = mean(Eug_indiv_per_ml_dominance, na.rm = TRUE),
Eup = mean(Eup_indiv_per_ml_dominance, na.rm = TRUE),
Lox = mean(Lox_indiv_per_ml_dominance, na.rm = TRUE),
Pau = mean(Pau_indiv_per_ml_dominance, na.rm = TRUE),
Pca = mean(Pca_indiv_per_ml_dominance, na.rm = TRUE),
Spi = mean(Spi_indiv_per_ml_dominance, na.rm = TRUE),
Spi_te = mean(Spi_te_indiv_per_ml_dominance, na.rm = TRUE),
Tet = mean(Tet_indiv_per_ml_dominance, na.rm = TRUE)
) %>%
pivot_longer(Ble:Tet, names_to = "species", values_to = "species_indiv_per_ml") %>%
ggplot(aes(
x = day,
y = species_indiv_per_ml,
group = interaction(day, species),
color = species
)) +
geom_point(position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(
aes(group = species),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
labs(x = axis_names %>%
filter(variable == "day") %>%
pull(axis_name),
y = axis_names %>%
filter(variable == "dominance") %>%
pull(axis_name)) +
coord_cartesian(ylim = c(0, 100))
print(p)
}
## [1] "Small connected to small"
## [1] "Small unconnected"
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
"water_addition_ml")
ecosystem_type_selected = c("Large connected to small",
"Large unconnected")
response_variable_selected = "shannon"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 2.9 0.59 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 1.2 0.377 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "bioarea_mm2_per_ml"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -7.4 0.003 *** strong
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -7 0.003 *** strong
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "species_richness"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.0210054 (tol = 0.002, component 1)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -4.8 0.012 ** moderate
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -6.4 0.004 *** strong
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "evenness_pielou"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 2.3 0.424 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 1 0.319 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "median_body_area_µm2"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 0.9 0.216 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -1.1 0.08 * weak
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
for(eco_type_i in 1:length(ecosystem_type_selected)){
print(ecosystem_type_selected[eco_type_i])
p = ds_ecosystems %>%
filter(ecosystem_type == ecosystem_type_selected[eco_type_i]) %>%
group_by(day) %>%
summarise(
Ble = mean(Ble_indiv_per_ml_dominance, na.rm = TRUE),
# Ble_se = sd(Ble_indiv_per_ml_dominance, na.rm = TRUE) / sqrt(n()),
# Ble_ci = qt(c(0.025, 0.975), df = n() - 1) * Ble_se,
Cep = mean(Cep_indiv_per_ml_dominance, na.rm = TRUE),
Col = mean(Col_indiv_per_ml_dominance, na.rm = TRUE),
Eug = mean(Eug_indiv_per_ml_dominance, na.rm = TRUE),
Eup = mean(Eup_indiv_per_ml_dominance, na.rm = TRUE),
Lox = mean(Lox_indiv_per_ml_dominance, na.rm = TRUE),
Pau = mean(Pau_indiv_per_ml_dominance, na.rm = TRUE),
Pca = mean(Pca_indiv_per_ml_dominance, na.rm = TRUE),
Spi = mean(Spi_indiv_per_ml_dominance, na.rm = TRUE),
Spi_te = mean(Spi_te_indiv_per_ml_dominance, na.rm = TRUE),
Tet = mean(Tet_indiv_per_ml_dominance, na.rm = TRUE)
) %>%
pivot_longer(Ble:Tet, names_to = "species", values_to = "species_indiv_per_ml") %>%
ggplot(aes(
x = day,
y = species_indiv_per_ml,
group = interaction(day, species),
color = species
)) +
geom_point(position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(
aes(group = species),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
labs(x = axis_names %>%
filter(variable == "day") %>%
pull(axis_name),
y = axis_names %>%
filter(variable == "dominance") %>%
pull(axis_name)) +
coord_cartesian(ylim = c(0, 100))
print(p)
}
## [1] "Large connected to small"
## [1] "Large unconnected"
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
"water_addition_ml")
ecosystem_type_selected = c("Large connected to small",
"Large connected to large")
response_variable_selected = "shannon"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 2.3 0.42 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 1 0.307 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "bioarea_mm2_per_ml"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -0.1 0.128 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -1.6 0.057 * weak
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "species_richness"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 0.4 0.168 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -0.9 0.086 * weak
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "evenness_pielou"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 3.2 0.661 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 2 0.873 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "median_body_area_µm2"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -7.1 0.004 *** strong
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -2.6 0.033 ** moderate
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
for(eco_type_i in 1:length(ecosystem_type_selected)){
print(ecosystem_type_selected[eco_type_i])
p = ds_ecosystems %>%
filter(ecosystem_type == ecosystem_type_selected[eco_type_i]) %>%
group_by(day) %>%
summarise(
Ble = mean(Ble_indiv_per_ml_dominance, na.rm = TRUE),
# Ble_se = sd(Ble_indiv_per_ml_dominance, na.rm = TRUE) / sqrt(n()),
# Ble_ci = qt(c(0.025, 0.975), df = n() - 1) * Ble_se,
Cep = mean(Cep_indiv_per_ml_dominance, na.rm = TRUE),
Col = mean(Col_indiv_per_ml_dominance, na.rm = TRUE),
Eug = mean(Eug_indiv_per_ml_dominance, na.rm = TRUE),
Eup = mean(Eup_indiv_per_ml_dominance, na.rm = TRUE),
Lox = mean(Lox_indiv_per_ml_dominance, na.rm = TRUE),
Pau = mean(Pau_indiv_per_ml_dominance, na.rm = TRUE),
Pca = mean(Pca_indiv_per_ml_dominance, na.rm = TRUE),
Spi = mean(Spi_indiv_per_ml_dominance, na.rm = TRUE),
Spi_te = mean(Spi_te_indiv_per_ml_dominance, na.rm = TRUE),
Tet = mean(Tet_indiv_per_ml_dominance, na.rm = TRUE)
) %>%
pivot_longer(Ble:Tet, names_to = "species", values_to = "species_indiv_per_ml") %>%
ggplot(aes(
x = day,
y = species_indiv_per_ml,
group = interaction(day, species),
color = species
)) +
geom_point(position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(
aes(group = species),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
labs(x = axis_names %>%
filter(variable == "day") %>%
pull(axis_name),
y = axis_names %>%
filter(variable == "dominance") %>%
pull(axis_name)) +
coord_cartesian(ylim = c(0, 100))
print(p)
}
## [1] "Large connected to small"
## [1] "Large connected to large"
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
"water_addition_ml")
ecosystem_type_selected = c("Large connected to large",
"Large unconnected")
response_variable_selected = "shannon"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 3.6 0.81 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 2 0.95 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "bioarea_mm2_per_ml"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 0.8 0.205 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 1.3 0.396 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "species_richness"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -0.6 0.103 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -1.9 0.048 ** moderate
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "evenness_pielou"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 1.86044 (tol = 0.002, component 1)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 0.3 0.161 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -1 0.081 * weak
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "median_body_area_µm2"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.011682 (tol = 0.002, component 1)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -14.9 < 0.001 **** very strong
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 -11.5 < 0.001 **** very strong
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
for(eco_type_i in 1:length(ecosystem_type_selected)){
print(ecosystem_type_selected[eco_type_i])
p = ds_ecosystems %>%
filter(ecosystem_type == ecosystem_type_selected[eco_type_i]) %>%
group_by(day) %>%
summarise(
Ble = mean(Ble_indiv_per_ml_dominance, na.rm = TRUE),
# Ble_se = sd(Ble_indiv_per_ml_dominance, na.rm = TRUE) / sqrt(n()),
# Ble_ci = qt(c(0.025, 0.975), df = n() - 1) * Ble_se,
Cep = mean(Cep_indiv_per_ml_dominance, na.rm = TRUE),
Col = mean(Col_indiv_per_ml_dominance, na.rm = TRUE),
Eug = mean(Eug_indiv_per_ml_dominance, na.rm = TRUE),
Eup = mean(Eup_indiv_per_ml_dominance, na.rm = TRUE),
Lox = mean(Lox_indiv_per_ml_dominance, na.rm = TRUE),
Pau = mean(Pau_indiv_per_ml_dominance, na.rm = TRUE),
Pca = mean(Pca_indiv_per_ml_dominance, na.rm = TRUE),
Spi = mean(Spi_indiv_per_ml_dominance, na.rm = TRUE),
Spi_te = mean(Spi_te_indiv_per_ml_dominance, na.rm = TRUE),
Tet = mean(Tet_indiv_per_ml_dominance, na.rm = TRUE)
) %>%
pivot_longer(Ble:Tet, names_to = "species", values_to = "species_indiv_per_ml") %>%
ggplot(aes(
x = day,
y = species_indiv_per_ml,
group = interaction(day, species),
color = species
)) +
geom_point(position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(
aes(group = species),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
labs(x = axis_names %>%
filter(variable == "day") %>%
pull(axis_name),
y = axis_names %>%
filter(variable == "dominance") %>%
pull(axis_name)) +
coord_cartesian(ylim = c(0, 100))
print(p)
}
## [1] "Large connected to large"
## [1] "Large unconnected"
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
"water_addition_ml")
ecosystem_type_selected = c("Medium unconnected",
"Medium connected to medium")
response_variable_selected = "shannon"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 2.4 0.461 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 1.8 0.625 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "bioarea_mm2_per_ml"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 1.9 0.35 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 1.5 0.489 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "species_richness"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 2.8 0.544 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 1.5 0.475 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "evenness_pielou"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 3.6 0.803 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 1.7 0.577 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
response_variable_selected = "median_body_area_µm2"
We want to know whether the connection influenced this response variable. We first start from plotting how this response variable changed in connected and unconnected ecosystems throughout the experiment through its mean ± 95 confidence interval:
# --- PLOT ORIGINAL DATA --- #
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
response_variable_selected)
Following the initial inspection, we proceed to analyse differences among ecosystems. Our first step involves filtering the data to isolate the relevant data for analysis. Specifically, we exclude data points where the response variable couldn’t be computed, as well as time points preceding the initial disturbance and resource flow. Then we plot the data to make sure that what filtered the data in the right way.
# --- FILTER DATA --- #
filtered_data = ds_ecosystems %>%
filter(time_point %in% time_points_model,
ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected)),
!is.na(!!sym("water_addition_ml")))
# --- PLOT FILTERED DATA --- #
plot.ecosystems.points(filtered_data,
ecosystem_type_selected,
response_variable_selected)
Then, given that we have gathered measurements from the same
ecosystem on multiple occasions, we can develop mixed effect models to
examine how the connection influenced this variable. To study the
effects of ecosystem connection we compare two models to a null model
using ANOVA: a full model and a reduced model. In all models, we treat
culture ID as having a random effect on how the slope and intercept of
the relationship between response variable and time, with the slope and
intercept being correlated (Bates et al.
2015). The full model contains the interaction of connection with
time
(Response variable ~ connection * day + (day | culture ID)),
the reduced model contains the connection but without the interaction
with time
(Response variable ~ connection + day + (day | culture ID)),
and the null model doesn’t contain the connection at all
(Response variable ~ day + (day | culture ID)). If any of
the two model comparisons is significant, then ecosystem connection had
an effect.
# --- ADD BASELINES --- #
baselines = ds_ecosystems %>%
filter(time_point == time_point_of_baselines) %>%
select(culture_ID,
all_of(response_variable_selected)) %>%
rename(baseline = all_of(response_variable_selected))
filtered_data = filtered_data %>%
left_join(baselines)
# --- COMPARE FULL, REDUCED, AND NULL MODEL --- #
full_model = lmer(get(response_variable_selected) ~
ecosystem_type * scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
reduced_model = lmer(get(response_variable_selected) ~
ecosystem_type +
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
null_model = lmer(get(response_variable_selected) ~
scale(day) +
scale(water_addition_ml) * scale(day) +
scale(baseline) * scale(day) +
(day | culture_ID),
data = filtered_data,
REML = FALSE)
Full model vs null model
# --- FULL VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(full_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 3.9 0.942 none
# --- FULL MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, full_model)
qqnorm(resid(full_model))
qqline(resid(full_model))
Reduced vs null model
# --- REDUCED VS NULL MODEL - SHOW MODEL STATS --- #
compute.model.stats(reduced_model,
null_model,
"mixed_model") %>%
print()
## deltaAIC p_value evidence
## 1 2 0.938 none
# --- REDUCED MODEL - SHOW RESIDUAL PLOTS --- #
create.res.vs.fit.ecos(filtered_data, reduced_model)
qqnorm(resid(reduced_model))
qqline(resid(reduced_model))
for(eco_type_i in 1:length(ecosystem_type_selected)){
print(ecosystem_type_selected[eco_type_i])
p = ds_ecosystems %>%
filter(ecosystem_type == ecosystem_type_selected[eco_type_i]) %>%
group_by(day) %>%
summarise(
Ble = mean(Ble_indiv_per_ml_dominance, na.rm = TRUE),
# Ble_se = sd(Ble_indiv_per_ml_dominance, na.rm = TRUE) / sqrt(n()),
# Ble_ci = qt(c(0.025, 0.975), df = n() - 1) * Ble_se,
Cep = mean(Cep_indiv_per_ml_dominance, na.rm = TRUE),
Col = mean(Col_indiv_per_ml_dominance, na.rm = TRUE),
Eug = mean(Eug_indiv_per_ml_dominance, na.rm = TRUE),
Eup = mean(Eup_indiv_per_ml_dominance, na.rm = TRUE),
Lox = mean(Lox_indiv_per_ml_dominance, na.rm = TRUE),
Pau = mean(Pau_indiv_per_ml_dominance, na.rm = TRUE),
Pca = mean(Pca_indiv_per_ml_dominance, na.rm = TRUE),
Spi = mean(Spi_indiv_per_ml_dominance, na.rm = TRUE),
Spi_te = mean(Spi_te_indiv_per_ml_dominance, na.rm = TRUE),
Tet = mean(Tet_indiv_per_ml_dominance, na.rm = TRUE)
) %>%
pivot_longer(Ble:Tet, names_to = "species", values_to = "species_indiv_per_ml") %>%
ggplot(aes(
x = day,
y = species_indiv_per_ml,
group = interaction(day, species),
color = species
)) +
geom_point(position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(
aes(group = species),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
labs(x = axis_names %>%
filter(variable == "day") %>%
pull(axis_name),
y = axis_names %>%
filter(variable == "dominance") %>%
pull(axis_name)) +
coord_cartesian(ylim = c(0, 100))
print(p)
}
## [1] "Medium unconnected"
## [1] "Medium connected to medium"
plot.ecosystems.points(ds_ecosystems,
ecosystem_type_selected,
"water_addition_ml")
We want here to plot the final paper version of the biodiversity and productivity of meta-ecosystems. We need to plot it again instead of using the plots we used in the analysis because we want to change the size of the plot.
# Define meta-ecosystems you want to plot.
metaecosystem_type_selected = c("Medium-Medium",
"Small-Large")
# Write function to plot a response variable. Afterwards you can use this function to plot alpha, beta, gamma diversity, and biomass.
plot.single.plot = function(response_variable_selected){
ds_metaecosystems %>%
filter(metaecosystem_type %in% metaecosystem_type_selected,
!is.na(!!sym(response_variable_selected))) %>%
summarySE(measurevar = response_variable_selected,
groupvars = c("day", "metaecosystem_type", "connection")) %>%
ggplot(aes(x = day,
y = get(response_variable_selected),
group = interaction(day, metaecosystem_type, connection),
color = metaecosystem_type,
linetype = connection)) +
geom_point(stat = "summary",
fun = "mean",
position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(stat = "summary",
fun = "mean",
aes(group = interaction(metaecosystem_type, connection)),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
geom_errorbar(aes(ymax = get(response_variable_selected) + ci,
ymin = get(response_variable_selected) - ci),
width = width_errorbar,
position = position_dodge(dodging)) +
labs(x = axis_names$axis_name[axis_names$variable == "day"],
y = axis_names$axis_name[axis_names$variable == response_variable_selected],
color = "") +
scale_color_manual(values = treatment_colours) +
scale_linetype_manual(values = treatment_linetype) +
geom_vline(xintercept = resource_flow_days,
linetype = resource_flow_line_type,
color = resource_flow_line_colour,
linewidth = resource_flow_line_width) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position,
legend.key.width = unit(legend_width_cm, "cm")) +
guides(color = guide_legend(title = NULL,
nrow = 2),
linetype = guide_legend(title = NULL,
nrow = 2)) +
theme(plot.margin = unit(c(ggarrange_margin_left,
ggarrange_margin_right,
ggarrange_margin_bottom,
ggarrange_margin_left),
"cm")) +
geom_rect(xmin = grey_background_xmin,
xmax = grey_background_xmax,
ymin = grey_background_ymin,
ymax = grey_background_ymax,
fill = grey_background_fill,
alpha = grey_background_alpha,
color = grey_background_color)
}
# Combine plots of alpha, beta, gamma biodiversity and biomass.
p_combined = ggarrange(plot.single.plot("mean_shannon") +
rremove("xlab") +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
font("legend.text", size = paper_labels_size) +
font("ylab", size = paper_labels_size),
plot.single.plot("bray_curtis") +
rremove("xlab") +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
font("legend.text",
size = paper_labels_size) +
font("ylab",
size = paper_labels_size),
plot.single.plot("metaecosystem_richness") +
rremove("xlab") +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
font("legend.text",
size = paper_labels_size) +
font("ylab",
size = paper_labels_size),
plot.single.plot("total_metaecosystem_bioarea_mm2") +
font("legend.text",
size = paper_labels_size) +
font("xlab",
size = paper_labels_size) +
font("ylab",
size = paper_labels_size) +
scale_x_continuous(breaks = unique(ds_metaecosystems$day)),
heights = c(0.8, 0.8, 0.8, 1),
nrow = 4,
common.legend = TRUE,
align = "v",
labels = c("(a)", "(b)", "(c)", "(d)"),
label.x = 0.1,
label.y = 0.8) %>%
print()
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's colour values.
## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's linetype values.
We want here to plot the final paper version of the biodiversity and productivity of the small and large ecosystems. We need to plot it again instead of using the plots we used in the analysis because we want to have the underscores in the legend. We don’t use underscores in the analysis because we can’t easily input them from a level name vector.
# Define ecosystems you want to plot.
ecosystem_type_selected = c("Small connected to large",
"Small connected to small",
"Small unconnected",
"Large connected to small",
"Large connected to large",
"Large unconnected")
# Construct function to plot how the response variable (biomass or Shannon) of small and large ecosystems changes across time.
plot.single.plot = function(response_variable_selected){
ds_ecosystems %>%
filter(ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected))) %>%
summarySE(measurevar = response_variable_selected,
groupvars = c("day", "time_point", "ecosystem_type", "ecosystem_size", "connection")) %>%
ggplot(aes(x = day,
y = get(response_variable_selected),
group = interaction(day, ecosystem_type),
color = ecosystem_type,
linetype = ecosystem_type)) +
geom_point(stat = "summary",
fun = "mean",
position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(stat = "summary",
fun = "mean",
aes(group = ecosystem_type),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
geom_errorbar(aes(ymax = get(response_variable_selected) + ci,
ymin = get(response_variable_selected) - ci),
width = width_errorbar,
position = position_dodge(dodging)) +
labs(x = axis_names$axis_name[axis_names$variable == "day"],
y = axis_names$axis_name[axis_names$variable == response_variable_selected],
color = "") +
scale_color_manual(values = c("#993404",
"#993404",
"#993404",
"#3182bd",
"#3182bd",
"#3182bd"),
label = expression(S[L],
S[S],
S,
L[S],
L[L],
L)) +
scale_linetype_manual(values = c("solid",
"dashed",
"dotted",
"solid",
"dashed",
"dotted"),
label = expression(S[L],
S[S],
S,
L[S],
L[L],
L)) +
geom_vline(xintercept = resource_flow_days,
linetype = resource_flow_line_type,
color = resource_flow_line_colour,
linewidth = resource_flow_line_width) +
geom_hline(yintercept = 0,
color = zero_line_colour,
linetype = zero_line_line_type,
linewidth = zero_line_line_width) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position,
legend.key.width = unit(legend_width_cm, "cm")) +
guides(color = guide_legend(title = NULL,
nrow = 3),
linetype = guide_legend(title = NULL,
nrow = 3)) +
geom_rect(xmin = grey_background_xmin,
xmax = grey_background_xmax,
ymin = grey_background_ymin,
ymax = grey_background_ymax,
fill = grey_background_fill,
alpha = grey_background_alpha,
color = grey_background_color)
}
# Combine plots
p_combined = ggarrange(plot.single.plot("shannon") +
rremove("xlab") +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
font("legend.text",
size = paper_labels_size) +
font("ylab",
size = paper_labels_size),
plot.single.plot("bioarea_mm2_per_ml") +
font("legend.text",
size = paper_labels_size) +
font("xlab",
size = paper_labels_size) +
font("ylab",
size = paper_labels_size) +
scale_x_continuous(breaks = unique(ds_ecosystems$day)),
heights = c(0.8, 0.8, 1),
nrow = 2,
align = "v",
labels = c("(a)", "(b)"),
label.x = 0.1,
label.y = 0.8,
common.legend = TRUE) %>%
print()
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
We want here to plot the final paper version of the biodiversity and productivity of the medium ecosystems. We need to plot it again instead of using the plots we used in the analysis because we want to have the underscores in the legend. We don’t use underscores in the analysis because we can’t easily input them from a level name vector.
# Define ecosystems you want to plot.
ecosystem_type_selected = c("Medium connected to medium",
"Medium unconnected")
# Construct function to plot how the response variable (biomass or Shannon) of small and large ecosystems changes across time.
plot.single.plot = function(response_variable_selected){
ds_ecosystems %>%
filter(ecosystem_type %in% ecosystem_type_selected,
!is.na(!!sym(response_variable_selected))) %>%
summarySE(measurevar = response_variable_selected,
groupvars = c("day", "time_point", "ecosystem_type", "ecosystem_size", "connection")) %>%
ggplot(aes(x = day,
y = get(response_variable_selected),
group = interaction(day, ecosystem_type),
color = ecosystem_type,
linetype = ecosystem_type)) +
geom_point(stat = "summary",
fun = "mean",
position = position_dodge(dodging),
size = treatment_points_size) +
geom_line(stat = "summary",
fun = "mean",
aes(group = ecosystem_type),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
geom_errorbar(aes(ymax = get(response_variable_selected) + ci,
ymin = get(response_variable_selected) - ci),
width = width_errorbar,
position = position_dodge(dodging)) +
labs(x = axis_names$axis_name[axis_names$variable == "day"],
y = axis_names$axis_name[axis_names$variable == response_variable_selected],
color = "") +
scale_color_manual(values = c("#d95f0e",
"#d95f0e"),
label = expression(M[M],
M)) +
scale_linetype_manual(values = c("dashed",
"dotted"),
label = expression(M[M],
M)) +
geom_vline(xintercept = resource_flow_days,
linetype = resource_flow_line_type,
color = resource_flow_line_colour,
linewidth = resource_flow_line_width) +
geom_hline(yintercept = 0,
color = zero_line_colour,
linetype = zero_line_line_type,
linewidth = zero_line_line_width) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position,
legend.key.width = unit(legend_width_cm, "cm")) +
guides(color = guide_legend(title = NULL,
nrow = 3),
linetype = guide_legend(title = NULL,
nrow = 3)) +
geom_rect(xmin = grey_background_xmin,
xmax = grey_background_xmax,
ymin = grey_background_ymin,
ymax = grey_background_ymax,
fill = grey_background_fill,
alpha = grey_background_alpha,
color = grey_background_color)
}
# Combine plots
p_combined = ggarrange(plot.single.plot("shannon") +
rremove("xlab") +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
font("legend.text",
size = paper_labels_size) +
font("ylab",
size = paper_labels_size),
plot.single.plot("bioarea_mm2_per_ml") +
font("legend.text",
size = paper_labels_size) +
font("xlab",
size = paper_labels_size) +
font("ylab",
size = paper_labels_size) +
scale_x_continuous(breaks = unique(ds_ecosystems$day)),
heights = c(0.8, 0.8, 1),
nrow = 2,
align = "v",
labels = c("(a)", "(b)"),
label.x = 0.1,
label.y = 0.8,
common.legend = TRUE) %>%
print()
We want here to plot the final paper version of the ratio between autotrophic and heterotrophic biomass in small, medium, and large unconnected ecosystems. We need to plot it again instead of using the plots we used in the analysis because we want to have S, M, and L in the legend.
# Define ecosystems and response variable you want to plot.
ecosystem_type_input = c("S",
"M",
"L")
response_variable = "auto_hetero_ratio"
# Construct plot
p = ds_ecosystems %>%
# Manipulate
mutate(ecosystem_type = case_when(ecosystem_type == "Small unconnected" ~ "S",
ecosystem_type == "Medium unconnected" ~ "M",
ecosystem_type == "Large unconnected" ~ "L")) %>%
filter(ecosystem_type %in% ecosystem_type_input,
!is.na(!!sym(response_variable))) %>%
summarySE(measurevar = response_variable,
groupvars = c("day", "ecosystem_type", "ecosystem_size", "connection")) %>%
# Create plot
ggplot(aes(x = day,
y = get(response_variable),
group = interaction(day, ecosystem_type),
color = ecosystem_type)) +
# Points
geom_point(stat = "summary",
fun = "mean",
position = position_dodge(dodging),
size = treatment_points_size) +
geom_errorbar(aes(ymax = get(response_variable) + ci,
ymin = get(response_variable) - ci),
width = width_errorbar,
position = position_dodge(dodging)) +
# Lines
geom_line(stat = "summary",
fun = "mean",
aes(group = ecosystem_type),
position = position_dodge(dodging),
linewidth = treatment_lines_linewidth) +
# Axes and legend
labs(x = axis_names$axis_name[axis_names$variable == "day"],
y = axis_names$axis_name[axis_names$variable == response_variable],
color = "") +
scale_x_continuous(breaks = unique(ds_ecosystems$day)) +
guides(color = guide_legend(title = NULL,
nrow = 1),
linetype = guide_legend(title = NULL,
nrow = 1)) +
scale_color_manual(values = c("#000000",
"#737373",
"#bdbdbd")) +
# Extra graphic elements
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = legend_position,
legend.key.width = unit(legend_width_cm, "cm"),
axis.title.x = element_text(size = paper_labels_size),
axis.title.y = element_text(size = paper_labels_size),
legend.text = element_text(size = paper_labels_size)) +
geom_rect(xmin = grey_background_xmin,
xmax = grey_background_xmax,
ymin = grey_background_ymin,
ymax = grey_background_ymax,
fill = grey_background_fill,
alpha = grey_background_alpha,
color = grey_background_color) +
geom_hline(yintercept = 0,
color = zero_line_colour,
linetype = zero_line_line_type,
linewidth = zero_line_line_width) +
geom_vline(xintercept = resource_flow_days,
linetype = resource_flow_line_type,
color = resource_flow_line_colour,
linewidth = resource_flow_line_width)
## Warning in qt(conf.interval/2 + 0.5, datac$N - 1): NaNs produced
p
During the experiment we noticed that microwaving ecosystem sub-samples for three minutes to create disturbance caused the evaporation of the ecosystems. However, we don’t know exactly how much evaporated and how much we should refill the ecosystems to bring them back to the original volume. Therefore, here I quantify the evaporation of 5.75 and 6.75 ml of deionised water, which represent low and high disturbance, respectively. For each disturbance level, I microwaved 15 tubes of that disturbance level for three minutes and measured their evaporation. To do so, I weighed the water before the microwaving (weigh tubes, add water, reweigh tubes) and after it (weigh Becker, pour water into it, reweigh Becker).
evaporation.test = read.csv(here("1_experiment", "evaporation_test","evaporation_test_initial.csv"), header = TRUE)
evaporation.test %>%
ggplot(aes (x = as.character(water_pipetted),
y = weight_water_evaporated,
group = interaction(water_pipetted, as.character(rack)),
fill = as.character(rack))) +
geom_boxplot(width = boxplot_width) +
labs(x = "Water volume (ml)" ,
y = "Evaporation (g)",
fill = "Rack replicate")
Furthermore, during the experiment we noticed that microwaving five 6.75 ml ecosystems sub-samples with ten empty tubes for three minutes to create disturbance caused the evaporation of the sub-samples more than if they were with other sub-samples. However, we don’t know exactly how much evaporated and how much we should refill the ecosystems to bring them back to the original volume. Therefore, here I quantify the evaporation of five 6.75 ml sub-samples with ten empty or filled falcon tubes. The weighting was conducted as above.
evaporation.test = read.csv(here("1_experiment", "evaporation_test", "evaporation_test_fill_nofill.csv"), header = TRUE)
evaporation.test %>%
ggplot(aes (x = all_tubes_water,
y = weight_water_evaporated)) +
geom_boxplot(width = boxplot_width) +
labs(x = "Water in the other 10 tubes" ,
y = "Evaporation (g)")
To analyse the videos I took of the ecosystems, I used the package BEMOVI. For this, I had to use the powerful computer. Below is the code utilised for video analysis on the powerful computer.
# Clear workspace
rm(list = ls())
# Set working directory
setwd("/media/mendel-himself/ID_061_Ema2/PatchSizePilot/training")
# Load required libraries
# library(devtools)
# install_github("femoerman/bemovi", ref="master")
library(bemovi)
library(parallel)
library(doParallel)
library(foreach)
# Define memory allocation parameters (in MB)
memory.alloc <- 240000 # Total memory allocated
memory.per.identifier <- 40000 # Memory per identifier
memory.per.linker <- 5000 # Memory per linker
memory.per.overlay <- 60000 # Memory per overlay
# Set paths for tools and particle linker
tools.path <- "/home/mendel-himself/bemovi_tools/" # Path to tools folder
to.particlelinker <- tools.path
# Set directories and file names
to.data <- paste(getwd(), "/", sep = "")
video.description.folder <- "0_video_description/"
video.description.file <- "video_description.txt"
raw.video.folder <- "1_raw/"
raw.avi.folder <- "1a_raw_avi/"
metadata.folder <- "1b_raw_meta/"
particle.data.folder <- "2_particle_data/"
trajectory.data.folder <- "3_trajectory_data/"
temp.overlay.folder <- "4a_temp_overlays/"
overlay.folder <- "4_overlays/"
merged.data.folder <- "5_merged_data/"
ijmacs.folder <- "ijmacs/"
######################################################################
# VIDEO PARAMETERS
# Define video parameters
fps <- 25 # Video frame rate (frames per second)
total_frames <- 125 # Total length of video (frames)
width <- 2048 # Video width (pixels)
height <- 2048 # Video height (pixels)
measured_volume <- 34.4 # Measured volume (microliters) for Leica M205 C with 1.6 fold magnification, sample height 0.5 mm and Hamamatsu Orca Flash 4
pixel_to_scale <- 4.05 # Size of a pixel (micrometers) for Leica M205 C with 1.6 fold magnification, sample height 0.5 mm and Hamamatsu Orca Flash 4
video.format <- "cxd" # Video file format (avi, cxd, mov, tiff)
difference.lag <- 10 # Difference lag
thresholds <- c(13, 255) # Threshold values of pixel intensity (considered a measure of pixel "whiteness") for determining if a pixel belongs to an individual rather than the background
######################################################################
# FILTERING PARAMETERS
# optimized for Perfex Pro 10 stereomicrocope with Perfex SC38800 (IDS UI-3880LE-M-GL) camera
# tested stereomicroscopes: Perfex Pro 10, Nikon SMZ1500, Leica M205 C
# tested cameras: Perfex SC38800, Canon 5D Mark III, Hamamatsu Orca Flash 4
# tested species: Tet, Col, Pau, Pca, Eug, Chi, Ble, Ceph, Lox, Spi
particle_min_size <- 10 # Minimum particle size (pixels)
particle_max_size <- 1000 # Maximum particle size (pixels)
trajectory_link_range <- 3 # Number of adjacent frames for linking particles
trajectory_displacement <- 16 # Maximum displacement of a particle between frames
# Filtering criteria
filter_min_net_disp <- 25 # Minimum net displacement (µm)
filter_min_duration <- 1 # Minimum duration (s)
filter_detection_freq <- 0.1 # Minimum detection frequency (1/s)
filter_median_step_length <- 3 # Minimum median step length (µm)
######################################################################
# VIDEO ANALYSIS
# Check if all tools are installed and set permissions
check_tools_folder(tools.path)
system(paste0("chmod a+x ", tools.path, "bftools/bf.sh"))
system(paste0("chmod a+x ", tools.path, "bftools/bfconvert"))
system(paste0("chmod a+x ", tools.path, "bftools/showinf"))
# Convert video files to compressed avi format
convert_to_avi(to.data,
raw.video.folder,
raw.avi.folder,
metadata.folder,
tools.path,
fps,
video.format)
# Uncomment the following lines for testing
# check_video_file_names(to.data, raw.avi.folder, video.description.folder, video.description.file)
# check_threshold_values(to.data, raw.avi.folder, ijmacs.folder, 2, difference.lag, thresholds, tools.path, memory.alloc)
# Identify particles in the video
locate_and_measure_particles(to.data,
raw.avi.folder,
particle.data.folder,
difference.lag,
min_size = particle_min_size,
max_size = particle_max_size,
thresholds = thresholds,
tools.path,
memory = memory.alloc,
memory.per.identifier = memory.per.identifier,
max.cores = detectCores() - 1)
# Link particles across frames to form trajectories
link_particles(to.data,
particle.data.folder,
trajectory.data.folder,
linkrange = trajectory_link_range,
disp = trajectory_displacement,
start_vid = 1,
memory = memory.alloc,
memory_per_linkerProcess = memory.per.linker,
raw.avi.folder,
max.cores = detectCores() - 1,
max_time = 1)
# Merge video description file with particle data
merge_data(to.data,
particle.data.folder,
trajectory.data.folder,
video.description.folder,
video.description.file,
merged.data.folder)
# Load the merged data
load(paste0(to.data, merged.data.folder, "Master.RData"))
# Filter trajectory data based on defined criteria
trajectory.data.filtered <- filter_data(trajectory.data,
filter_min_net_disp,
filter_min_duration,
filter_detection_freq,
filter_median_step_length)
# Summarize trajectory data to individual-based data
morph_mvt <- summarize_trajectories(trajectory.data.filtered,
calculate.median = F,
write = T,
to.data,
merged.data.folder)
# Summarize sample level data
summarize_populations(trajectory.data.filtered,
morph_mvt,
write = T,
to.data,
merged.data.folder,
video.description.folder,
video.description.file,
total_frames)
# Create overlays for validation
create.subtitle.overlays(to.data,
traj.data = trajectory.data.filtered,
raw.video.folder,
raw.avi.folder,
temp.overlay.folder,
overlay.folder,
fps,
vid.length = total_frames / fps,
width,
height,
tools.path = tools.path,
overlay.type = "number",
video.format)
# Create overlays (old method)
create_overlays(traj.data = trajectory.data.filtered,
to.data = to.data,
merged.data.folder = merged.data.folder,
raw.video.folder = raw.avi.folder,
temp.overlay.folder = "4a_temp_overlays_old/",
overlay.folder = "4_overlays_old/",
width = width,
height = height,
difference.lag = difference.lag,
type = "traj",
predict_spec = F,
contrast.enhancement = 1,
IJ.path = "/home/mendel-himself/bemovi_tools",
memory = memory.alloc,
max.cores = detectCores() - 1,
memory.per.overlay = memory.per.overlay)
To avoid transferring all the data from the powerful computer, I performed species identification on that system and subsequently imported the results into the Rstudio folder on my personal computer. Below is the code utilised for species identification on the powerful computer.
# Clear the workspace
rm(list = ls())
# Uncomment and install required packages if not already installed
#install.packages("e1071",dependencies = T)
#install.packages("devtools",dependencies = T)
#install_github("pennekampster/bemovi", ref="master")
#library(devtools)
# Load required libraries
library(bemovi)
library(e1071)
library("here")
library("tidyverse")
# Define time points in the experiment
time_points_in_experiment = c("t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7")
# Loop through each time point in the experiment
for (time_point in time_points_in_experiment) {
# Define folder names and paths
video.description.folder = "0_video_description/"
video.description.file = "video_description.txt"
merged.data.folder = "5_merged_data/"
monocultures_folder_path = here("biomass_analysis", "training", "")
mixed_cultures_folder_path = here("biomass_analysis", time_point, "")
#Parameters used in the video analysis script
fps = 25
nsv = 5
measured_volume = 34.4
pixel_to_scale = 4.05
filter_min_net_disp = 25
filter_min_duration = 1
filter_detection_freq = 0.1
filter_median_step_length = 3
# Load master dataset of mono-cultures
load(paste0(monocultures_folder_path, merged.data.folder, "Master.RData"))
trajectory.data_monocultures = trajectory.data
rm(trajectory.data)
# Filter the master data of mono-cultures using the same parameters as in the video analysis script
trajectory.data_monocultures.filtered = filter_data(trajectory.data_monocultures,
filter_min_net_disp,
filter_min_duration,
filter_detection_freq,
filter_median_step_length)
# Summarize trajectory data to individual-based data
morph_mvt = summarize_trajectories(data = trajectory.data_monocultures.filtered,
calculate.median = FALSE,
write = TRUE,
to.data = monocultures_folder_path,
merged.data.folder = merged.data.folder) %>%
mutate(comment = NULL)
# Prepare training data by removing incomplete cases
training_data = morph_mvt[complete.cases(morph_mvt), ]
# Train SVM model on the training data
svm1 = svm(
factor(species) ~
mean_grey +
sd_grey +
mean_area +
sd_area +
mean_perimeter +
mean_turning +
sd_turning +
sd_perimeter +
mean_major +
sd_major +
mean_minor +
sd_minor +
mean_ar +
sd_ar +
duration +
max_net +
net_disp +
net_speed +
gross_disp +
max_step +
min_step +
sd_step +
sd_gross_speed +
max_gross_speed +
min_gross_speed ,
data = training_data,
probability = T,
na.action = na.pass)
# Generate and print confusion matrix
confusion.matrix = table(svm1$fitted, training_data$species)
confusion.matrix.nd = confusion.matrix
diag(confusion.matrix.nd) = 0
svm1$confusion = cbind(confusion.matrix,
class.error = rowSums(confusion.matrix.nd) / rowSums(confusion.matrix))
print(paste("Confusion matrix of time point", time_point))
print(svm1$confusion)
# Extract unique species names
species.names = unique(trajectory.data_monocultures$species)
# Load mixed cultures dataset
load(paste0(mixed_cultures_folder_path, merged.data.folder, "Master.RData"))
trajectory.data_mixed = trajectory.data
rm(trajectory.data)
# Filter mixed cultures data using the same parameters
trajectory.data_mixed.filtered = filter_data(trajectory.data_mixed,
filter_min_net_disp,
filter_min_duration,
filter_detection_freq,
filter_median_step_length)
# Summarize trajectory data to individual-based data
morph_mvt = summarize_trajectories(data = trajectory.data_mixed.filtered,
calculate.median = FALSE,
write = TRUE,
to.data = mixed_cultures_folder_path,
merged.data.folder = merged.data.folder)[, which(colnames(morph_mvt) != "Col_manual")] %>%
mutate(comment = NULL)
# Prepare data for prediction by removing incomplete cases
data.to.predict = morph_mvt[complete.cases(morph_mvt),]
# Predict species using the trained SVM model
p.id = predict(object = svm1, data.to.predict, type = "response")
data.to.predict$predicted_species = as.character(p.id)
# Summarize population data
pop.data = summarize_populations(traj.data = trajectory.data_monocultures.filtered,
sum.data = morph_mvt,
write = TRUE,
to.data = mixed_cultures_folder_path,
merged.data.folder = merged.data.folder,
video.description.folder = video.description.folder,
video.description.file = video.description.file,
total_frame = fps * nsv)
# Function to calculate species density
species.density = function(sample_output,
indiv_predicted,
species_names,
total_frames,
mv = measured_volume) {
samples = unique(indiv_predicted$file)
sp.dens = matrix(0,
nrow(sample_output),
length(species_names))
colnames(sp.dens) = species_names
for (i in 1:length(samples)) {
indiv = subset(indiv_predicted, file == samples[i])
spec = unique(indiv$predicted_species)
for (j in 1:length(spec)) {
all.indiv.sp = subset(indiv,
predicted_species == spec[j])
dens = sum(all.indiv.sp$N_frames) / total_frames / mv
sp.dens[which(sample_output$file == as.character(samples[i])), which(species_names == spec[j])] = dens
}
}
return(cbind(sample_output, sp.dens))
}
# Calculate species density for the current time point
output = species.density(pop.data,
data.to.predict,
species.names,
total_frames = fps * nsv,
mv = measured_volume)
# Save the species density results to a CSV file
file_name = paste0("species_ID_", time_point, ".csv")
write.csv(output, here("biomass_analysis", "species_ID_results", file_name))
rm(output)
}
## Time difference of 1.8 mins
Check that disturbance_global_selected is what you set:
print(paste0("Disturbance = ", disturbance_global_selected))
## [1] "Disturbance = high"
If you want to change a certain part of the code using the following code in Unix:
#Rmd script
cd /Users/Ema/Documents/Github/PatchSize/3_r_files
sed -i '' 's/old_string/new_string/g' *.Rmd
#R script
cd /Users/ema/Documents/GitHub/PatchSize/3_r_files/functions
sed -i '' 's/old_string/new_string/g' *.R
you want to share a dataset and get a reproducible object, use the following R code:
dput()
The only type of ecosystem where all cultures crashed was small connected to small at high disturbance.
R.version.string
## [1] "R version 4.3.2 (2023-10-31)"
The R packages we used with their version are as follows:
sessionInfo()
## R version 4.3.2 (2023-10-31)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Sonoma 14.2.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: Europe/Zurich
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices datasets utils methods base
##
## other attached packages:
## [1] conflicted_1.2.0 broom.mixed_0.2.9.5 emmeans_1.10.4
## [4] combinat_0.0-8 Rmisc_1.5.1 betapart_1.6
## [7] vegan_2.6-6.1 lattice_0.22-6 permute_0.9-7
## [10] lmerTest_3.1-3 lme4_1.1-35.4 Matrix_1.6-5
## [13] GGally_2.2.1 gridExtra_2.3 plotly_4.10.4
## [16] ggpubr_0.6.0 lubridate_1.9.3 forcats_1.0.0
## [19] stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2
## [22] readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
## [25] ggplot2_3.5.1 tidyverse_2.0.0 plyr_1.8.9
## [28] renv_1.0.7.9000 testthat_3.2.1.1 here_1.0.1
##
## loaded via a namespace (and not attached):
## [1] RColorBrewer_1.1-3 rstudioapi_0.16.0 jsonlite_1.8.8
## [4] magrittr_2.0.3 estimability_1.5.1 farver_2.1.2
## [7] nloptr_2.1.1 rmarkdown_2.27 vctrs_0.6.5
## [10] memoise_2.0.1 minqa_1.2.7 rstatix_0.7.2
## [13] htmltools_0.5.8.1 itertools_0.1-3 broom_1.0.6
## [16] sass_0.4.9 parallelly_1.38.0 pracma_2.4.4
## [19] bslib_0.7.0 htmlwidgets_1.6.4 desc_1.4.3
## [22] cachem_1.1.0 lifecycle_1.0.4 minpack.lm_1.2-4
## [25] iterators_1.0.14 pkgconfig_2.0.3 optimx_2023-10.21
## [28] R6_2.5.1 fastmap_1.2.0 future_1.34.0
## [31] magic_1.6-1 digest_0.6.36 numDeriv_2016.8-1.1
## [34] colorspace_2.1-0 furrr_0.3.1 rprojroot_2.0.4
## [37] pkgload_1.3.4 crosstalk_1.2.1 labeling_0.4.3
## [40] fansi_1.0.6 timechange_0.3.0 httr_1.4.7
## [43] abind_1.4-5 mgcv_1.9-0 compiler_4.3.2
## [46] withr_3.0.0 backports_1.5.0 carData_3.0-5
## [49] ggstats_0.6.0 highr_0.11 ggsignif_0.6.4
## [52] MASS_7.3-60 tools_4.3.2 ape_5.8
## [55] glue_1.7.0 rcdd_1.6 nlme_3.1-163
## [58] grid_4.3.2 cluster_2.1.4 generics_0.1.3
## [61] snow_0.4-4 gtable_0.3.5 tzdb_0.4.0
## [64] data.table_1.15.4 hms_1.1.3 car_3.1-2
## [67] utf8_1.2.4 foreach_1.5.2 pillar_1.9.0
## [70] splines_4.3.2 tidyselect_1.2.1 knitr_1.47
## [73] xfun_0.45 brio_1.1.5 stringi_1.8.4
## [76] lazyeval_0.2.2 yaml_2.3.8 boot_1.3-30
## [79] evaluate_0.24.0 codetools_0.2-20 cli_3.6.3
## [82] geometry_0.4.7 munsell_0.5.1 jquerylib_0.1.4
## [85] Rcpp_1.0.12 doSNOW_1.0.20 globals_0.16.3
## [88] coda_0.19-4.1 parallel_4.3.2 picante_1.8.2
## [91] listenv_0.9.1 viridisLite_0.4.2 mvtnorm_1.3-1
## [94] scales_1.3.0 rlang_1.1.4 cowplot_1.1.3
## [97] fastmatch_1.1-4 waldo_0.5.2